home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / benchmarks / itc / cc1.spur / decl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-08-30  |  98.3 KB  |  3,220 lines

  1. /* Process declarations and variables for C compiler.
  2.    Copyright (C) 1988 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY.  No author or distributor
  8. accepts responsibility to anyone for the consequences of using it
  9. or for whether it serves any particular purpose or works at all,
  10. unless he says so in writing.  Refer to the GNU CC General Public
  11. License for full details.
  12.  
  13. Everyone is granted permission to copy, modify and redistribute
  14. GNU CC, but only under the conditions described in the
  15. GNU CC General Public License.   A copy of this license is
  16. supposed to have been given to you along with GNU CC so you
  17. can know your rights and responsibilities.  It should be in a
  18. file named COPYING.  Among other things, the copyright notice
  19. and this notice must be preserved on all copies.  */
  20.  
  21.  
  22. /* Process declarations and symbol lookup for C front end.
  23.    Also constructs types; the standard scalar types at initialization,
  24.    and structure, union, array and enum types when they are declared.  */
  25.  
  26. /* ??? not all decl nodes are given the most useful possible
  27.    line numbers.  For example, the CONST_DECLs for enum values.  */
  28.  
  29. #include "config.h"
  30. #include "tree.h"
  31. #include "flags.h"
  32. #include "c-tree.h"
  33. #include "parse.h"
  34.  
  35. /* In grokdeclarator, distinguish syntactic contexts of declarators.  */
  36. enum decl_context
  37. { NORMAL,            /* Ordinary declaration */
  38.   FUNCDEF,            /* Function definition */
  39.   PARM,                /* Declaration of parm before function body */
  40.   FIELD,            /* Declaration inside struct or union */
  41.   TYPENAME};            /* Typename (inside cast or sizeof)  */
  42.  
  43. #define NULL 0
  44. #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
  45. #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
  46.  
  47. static tree grokparms (), grokdeclarator ();
  48. tree pushdecl ();
  49. tree make_index_type ();
  50. static void builtin_function ();
  51.  
  52. static tree lookup_tag ();
  53. static tree lookup_tag_reverse ();
  54. static tree lookup_name_current_level ();
  55. static char *redeclaration_error_message ();
  56.  
  57. /* a node which has tree code ERROR_MARK, and whose type is itself.
  58.    All erroneous expressions are replaced with this node.  All functions
  59.    that accept nodes as arguments should avoid generating error messages
  60.    if this node is one of the arguments, since it is undesirable to get
  61.    multiple error messages from one error in the input.  */
  62.  
  63. tree error_mark_node;
  64.  
  65. /* INTEGER_TYPE and REAL_TYPE nodes for the standard data types */
  66.  
  67. tree short_integer_type_node;
  68. tree integer_type_node;
  69. tree long_integer_type_node;
  70. tree long_long_integer_type_node;
  71.  
  72. tree short_unsigned_type_node;
  73. tree unsigned_type_node;
  74. tree long_unsigned_type_node;
  75. tree long_long_unsigned_type_node;
  76.  
  77. tree unsigned_char_type_node;
  78. tree signed_char_type_node;
  79. tree char_type_node;
  80.  
  81. tree float_type_node;
  82. tree double_type_node;
  83. tree long_double_type_node;
  84.  
  85. /* a VOID_TYPE node.  */
  86.  
  87. tree void_type_node;
  88.  
  89. /* A node for type `void *'.  */
  90.  
  91. tree ptr_type_node;
  92.  
  93. /* A node for type `char *'.  */
  94.  
  95. tree string_type_node;
  96.  
  97. /* Type `char[256]' or something like it.
  98.    Used when an array of char is needed and the size is irrelevant.  */
  99.  
  100. tree char_array_type_node;
  101.  
  102. /* Type `int[256]' or something like it.
  103.    Used when an array of int needed and the size is irrelevant.  */
  104.  
  105. tree int_array_type_node;
  106.  
  107. /* type `int ()' -- used for implicit declaration of functions.  */
  108.  
  109. tree default_function_type;
  110.  
  111. /* function types `double (double)' and `double (double, double)', etc.  */
  112.  
  113. tree double_ftype_double, double_ftype_double_double;
  114. tree int_ftype_int, long_ftype_long;
  115.  
  116. /* Function type `void (void *, void *, int)' and similar ones */
  117.  
  118. tree void_ftype_ptr_ptr_int, int_ftype_ptr_ptr_int, void_ftype_ptr_int_int;
  119.  
  120. /* Two expressions that are constants with value zero.
  121.    The first is of type `int', the second of type `void *'.  */
  122.  
  123. tree integer_zero_node;
  124. tree null_pointer_node;
  125.  
  126. /* A node for the integer constant 1.  */
  127.  
  128. tree integer_one_node;
  129.  
  130. /* An identifier whose name is <value>.  This is used as the "name"
  131.    of the RESULT_DECLs for values of functions.  */
  132.  
  133. tree value_identifier;
  134.  
  135. /* While defining an enum type, this is 1 plus the last enumerator
  136.    constant value.  */
  137.  
  138. static tree enum_next_value;
  139.  
  140. /* Parsing a function declarator leaves a list of parameter names
  141.    or a chain or parameter decls here.  */
  142.  
  143. static tree last_function_parms;
  144.  
  145. /* Parsing a function declarator leaves here a chain of structure
  146.    and enum types declared in the parmlist.  */
  147.  
  148. static tree last_function_parm_tags;
  149.  
  150. /* After parsing the declarator that starts a function definition,
  151.    `start_function' puts here the list of parameter names or chain of decls.
  152.    `store_parm_decls' finds it here.  */
  153.  
  154. static tree current_function_parms;
  155.  
  156. /* Similar, for last_function_parm_tags.  */
  157. static tree current_function_parm_tags;
  158.  
  159. /* A list (chain of TREE_LIST nodes) of all LABEL_STMTs in the function
  160.    that have names.  Here so we can clear out their names' definitions
  161.    at the end of the function.  */
  162.  
  163. static tree named_labels;
  164.  
  165. /* The FUNCTION_DECL for the function currently being compiled,
  166.    or 0 if between functions.  */
  167. tree current_function_decl;
  168.  
  169. /* Set to 0 at beginning of a function definition, set to 1 if
  170.    a return statement that specifies a return value is seen.  */
  171.  
  172. int current_function_returns_value;
  173.  
  174. /* Set to 0 at beginning of a function definition, set to 1 if
  175.    a return statement with no argument is seen.  */
  176.  
  177. int current_function_returns_null;
  178.  
  179. /* Set to nonzero by `grokdeclarator' for a function
  180.    whose return type is defaulted, if warnings for this are desired.  */
  181.  
  182. static int warn_about_return_type;
  183.  
  184. /* For each binding contour we allocate a binding_level structure
  185.  * which records the names defined in that contour.
  186.  * Contours include:
  187.  *  0) the global one
  188.  *  1) one for each function definition,
  189.  *     where internal declarations of the parameters appear.
  190.  *  2) one for each compound statement,
  191.  *     to record its declarations.
  192.  *
  193.  * The current meaning of a name can be found by searching the levels from
  194.  * the current one out to the global one.
  195.  */
  196.  
  197. /* Note that the information in the `names' component of the global contour
  198.    is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers.  */
  199.  
  200. struct binding_level
  201.   {
  202.     /* A chain of _DECL nodes for all variables, constants, functions,
  203.        and typedef types.  These are in the reverse of the order supplied.
  204.      */
  205.     tree names;
  206.  
  207.     /* A list of structure, union and enum definitions,
  208.      * for looking up tag names.
  209.      * It is a chain of TREE_LIST nodes, each of whose TREE_PURPOSE is a name,
  210.      * or NULL_TREE; and whose TREE_VALUE is a RECORD_TYPE, UNION_TYPE,
  211.      * or ENUMERAL_TYPE node.
  212.      */
  213.     tree tags;
  214.  
  215.     /* For each level, a list of shadowed outer-level local definitions
  216.        to be restored when this level is popped.
  217.        Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
  218.        whose TREE_VALUE is its old definition (a kind of ..._DECL node).  */
  219.     tree shadowed;
  220.  
  221.     /* For each level (except not the global one),
  222.        a chain of LET_STMT nodes for all the levels
  223.        that were entered and exited one level down.  */
  224.     tree blocks;
  225.  
  226.     /* The binding level which this one is contained in (inherits from).  */
  227.     struct binding_level *level_chain;
  228.  
  229.     /* Nonzero for the level that holds the parameters of a function.  */
  230.     char parm_flag;
  231.  
  232.     /* Nonzero if this level "doesn't exist" for tags.  */
  233.     char tag_transparent;
  234.  
  235.     /* Number of decls in `names' that have incomplete 
  236.        structure or union types.  */
  237.     int n_incomplete;
  238.   };
  239.  
  240. #define NULL_BINDING_LEVEL (struct binding_level *) NULL
  241.   
  242. /* The binding level currently in effect.  */
  243.  
  244. static struct binding_level *current_binding_level;
  245.  
  246. /* A chain of binding_level structures awaiting reuse.  */
  247.  
  248. static struct binding_level *free_binding_level;
  249.  
  250. /* The outermost binding level, for names of file scope.
  251.    This is created when the compiler is started and exists
  252.    through the entire run.  */
  253.  
  254. static struct binding_level *global_binding_level;
  255.  
  256. /* Binding level structures are initialized by copying this one.  */
  257.  
  258. static struct binding_level clear_binding_level
  259.   = {NULL, NULL, NULL, NULL, NULL, 0, 0, 0};
  260.  
  261. /* Create a new `struct binding_level'.  */
  262.  
  263. static
  264. struct binding_level *
  265. make_binding_level ()
  266. {
  267.   /* NOSTRICT */
  268.   return (struct binding_level *) xmalloc (sizeof (struct binding_level));
  269. }
  270.  
  271. /* Nonzero if we are currently in the global binding level.  */
  272.  
  273. int
  274. global_bindings_p ()
  275. {
  276.   return current_binding_level == global_binding_level;
  277. }
  278.  
  279. /* Enter a new binding level.
  280.    If TAG_TRANSPARENT is nonzero, do so only for the name space of variables,
  281.    not for that of tags.  */
  282.  
  283. void
  284. pushlevel (tag_transparent)
  285.      int tag_transparent;
  286. {
  287.   register struct binding_level *newlevel = NULL_BINDING_LEVEL;
  288.  
  289.   /* If this is the top level of a function,
  290.      just make sure that NAMED_LABELS is 0.
  291.      They should have been set to 0 at the end of the previous function.  */
  292.  
  293.   if (current_binding_level == global_binding_level)
  294.     {
  295.       if (named_labels)
  296.     abort ();
  297.     }
  298.  
  299.   /* Reuse or create a struct for this binding level.  */
  300.  
  301.   if (free_binding_level)
  302.     {
  303.       newlevel = free_binding_level;
  304.       free_binding_level = free_binding_level->level_chain;
  305.     }
  306.   else
  307.     {
  308.       newlevel = make_binding_level ();
  309.     }
  310.  
  311.   /* Add this level to the front of the chain (stack) of levels that
  312.      are active.  */
  313.  
  314.   *newlevel = clear_binding_level;
  315.   newlevel->level_chain = current_binding_level;
  316.   current_binding_level = newlevel;
  317.   newlevel->tag_transparent = tag_transparent;
  318. }
  319.  
  320. /* Exit a binding level.
  321.    Pop the level off, and restore the state of the identifier-decl mappings
  322.    that were in effect when this level was entered.
  323.  
  324.    If KEEP is nonzero, this level had explicit declarations, so
  325.    and create a "block" (a LET_STMT node) for the level
  326.    to record its declarations and subblocks for symbol table output.
  327.  
  328.    If FUNCTIONBODY is nonzero, this level is the body of a function,
  329.    so create a block as if KEEP were set and also clear out all
  330.    label names.
  331.  
  332.    If REVERSE is nonzero, reverse the order of decls before putting
  333.    them into the LET_STMT.  */
  334.  
  335. void
  336. poplevel (keep, reverse, functionbody)
  337.      int keep;
  338.      int reverse;
  339.      int functionbody;
  340. {
  341.   register tree link;
  342.   /* The chain of decls was accumulated in reverse order.
  343.      Put it into forward order, just for cleanliness.  */
  344.   tree decls;
  345.   tree tags = current_binding_level->tags;
  346.   tree subblocks = current_binding_level->blocks;
  347.   tree block = 0;
  348.  
  349.   /* This warning is turned off because it causes warnings for
  350.      declarations like `extern struct foo *x'.  */
  351. #if 0
  352.   /* Warn about incomplete structure types in this level.  */
  353.   for (link = tags; link; link = TREE_CHAIN (link))
  354.     if (TYPE_SIZE (TREE_VALUE (link)) == 0)
  355.       {
  356.     tree type = TREE_VALUE (link);
  357.     char *errmsg;
  358.     switch (TREE_CODE (type))
  359.       {
  360.       case RECORD_TYPE:
  361.         errmsg = "`struct %s' incomplete in scope ending here";
  362.         break;
  363.       case UNION_TYPE:
  364.         errmsg = "`union %s' incomplete in scope ending here";
  365.         break;
  366.       case ENUMERAL_TYPE:
  367.         errmsg = "`enum %s' incomplete in scope ending here";
  368.         break;
  369.       }
  370.     if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
  371.       error (errmsg, IDENTIFIER_POINTER (TYPE_NAME (type)));
  372.     else
  373.       /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL.  */
  374.       error (errmsg, IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))));
  375.       }
  376. #endif /* 0 */
  377.  
  378.   /* Get the decls in the order they were written.
  379.      Usually current_binding_level->names is in reverse order.
  380.      But parameter decls were previously put in forward order.  */
  381.  
  382.   if (reverse)
  383.     current_binding_level->names
  384.       = decls = nreverse (current_binding_level->names);
  385.   else
  386.     decls = current_binding_level->names;
  387.  
  388.   /* If there were any declarations or structure tags in that level,
  389.      or if this level is a function body,
  390.      create a LET_STMT to record them for the life of this function.  */
  391.  
  392.   if (keep || functionbody)
  393.     block = build_let (0, 0, keep ? decls : 0,
  394.                subblocks, 0, keep ? tags : 0);
  395.  
  396.   /* In each subblock, record that this is its superior.  */
  397.  
  398.   for (link = subblocks; link; link = TREE_CHAIN (link))
  399.     STMT_SUPERCONTEXT (link) = block;
  400.  
  401.   /* Clear out the meanings of the local variables of this level;
  402.      also record in each decl which block it belongs to.  */
  403.  
  404.   for (link = decls; link; link = TREE_CHAIN (link))
  405.     {
  406.       if (DECL_NAME (link) != 0)
  407.     IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = 0;
  408.       DECL_CONTEXT (link) = block;
  409.     }
  410.  
  411.   /* Restore all name-meanings of the outer levels
  412.      that were shadowed by this level.  */
  413.  
  414.   for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
  415.     IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
  416.  
  417.   /* If the level being exited is the top level of a function,
  418.      check over all the labels.  */
  419.  
  420.   if (functionbody)
  421.     {
  422.       /* Clear out the definitions of all label names,
  423.      since their scopes end here.  */
  424.  
  425.       for (link = named_labels; link; link = TREE_CHAIN (link))
  426.     {
  427.       if (DECL_SOURCE_LINE (TREE_VALUE (link)) == 0)
  428.         {
  429.           error ("label `%s' used somewhere above but not defined",
  430.              IDENTIFIER_POINTER (DECL_NAME (TREE_VALUE (link))));
  431.           /* Avoid crashing later.  */
  432.           define_label (input_filename, 1, DECL_NAME (TREE_VALUE (link)));
  433.         }
  434.       IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link))) = 0;
  435.     }
  436.  
  437.       named_labels = 0;
  438.     }
  439.  
  440.   /* Pop the current level, and free the structure for reuse.  */
  441.  
  442.   {
  443.     register struct binding_level *level = current_binding_level;
  444.     current_binding_level = current_binding_level->level_chain;
  445.  
  446.     level->level_chain = free_binding_level;
  447.     free_binding_level = level;
  448.   }
  449.  
  450.   if (functionbody)
  451.     {
  452.       DECL_INITIAL (current_function_decl) = block;
  453.       /* If this is the top level block of a function,
  454.      the vars are the function's parameters.
  455.      Don't leave them in the LET_STMT because they are
  456.      found in the FUNCTION_DECL instead.  */
  457.       STMT_VARS (block) = 0;
  458.     }
  459.   else if (block)
  460.     current_binding_level->blocks
  461.       = chainon (current_binding_level->blocks, block);
  462.   /* If we did not make a block for the level just exited,
  463.      any blocks made for inner levels
  464.      (since they cannot be recorded as subblocks in that level)
  465.      must be carried forward so they will later become subblocks
  466.      of something else.  */
  467.   else if (subblocks)
  468.     current_binding_level->blocks
  469.       = chainon (current_binding_level->blocks, subblocks);
  470.     
  471. }
  472.  
  473. /* Push a definition of struct, union or enum tag "name".
  474.    "type" should be the type node.
  475.    We assume that the tag "name" is not already defined.
  476.  
  477.    Note that the definition may really be just a forward reference.
  478.    In that case, the TYPE_SIZE will be zero.  */
  479.  
  480. void
  481. pushtag (name, type)
  482.      tree name, type;
  483. {
  484.   register struct binding_level *b = current_binding_level;
  485.   while (b->tag_transparent) b = b->level_chain;
  486.  
  487.   if (name)
  488.     {
  489.       /* Record the identifier as the type's name if it has none.  */
  490.  
  491.       if (TYPE_NAME (type) == 0)
  492.     TYPE_NAME (type) = name;
  493.  
  494.       b->tags = tree_cons (name, type, b->tags);
  495.     }
  496. }
  497.  
  498. /* Handle when a new declaration NEW has the same name as an old one OLD
  499.    in the same binding contour.  Prints an error message if appropriate.
  500.  
  501.    If safely possible, alter OLD to look like NEW, and return 1.
  502.    Otherwise, return 0.  */
  503.  
  504. static int
  505. duplicate_decls (new, old)
  506.      register tree new, old;
  507. {
  508.   int types_match = comptypes (TREE_TYPE (new), TREE_TYPE (old));
  509.  
  510.   /* If this decl has linkage, and the old one does too, maybe no error.  */
  511.   if (TREE_CODE (old) != TREE_CODE (new))
  512.     {
  513.       error_with_decl (new, "`%s' redeclared as different kind of symbol");
  514.       error_with_decl (old, "previous declaration of `%s'");
  515.     }
  516.   else
  517.     {
  518.       if (!types_match)
  519.     {
  520.       error_with_decl (new, "conflicting types for `%s'");
  521.       error_with_decl (old, "previous declaration of `%s'");
  522.     }
  523.       else
  524.     {
  525.       char *errmsg = redeclaration_error_message (new, old);
  526.       if (errmsg)
  527.         {
  528.           error_with_decl (new, errmsg);
  529.           error_with_decl (old, "previous declaration of `%s'");
  530.         }
  531.     }
  532.     }
  533.  
  534.   if (TREE_CODE (old) == TREE_CODE (new))
  535.     {
  536.       /* Copy all the DECL_... slots specified in the new decl
  537.      except for any that we copy here from the old type.  */
  538.  
  539.       if (types_match)
  540.     {
  541.       tree oldtype = TREE_TYPE (old);
  542.       /* Merge the data types specified in the two decls.  */
  543.       TREE_TYPE (new)
  544.         = TREE_TYPE (old) = commontype (TREE_TYPE (new), TREE_TYPE (old));
  545.  
  546.       /* Lay the type out, unless already done.  */
  547.       if (oldtype != TREE_TYPE (new))
  548.         {
  549.           if (TREE_TYPE (new) != error_mark_node)
  550.         layout_type (TREE_TYPE (new));
  551.           if (TREE_CODE (new) != FUNCTION_DECL
  552.           && TREE_CODE (new) != TYPE_DECL
  553.           && TREE_CODE (new) != CONST_DECL)
  554.         layout_decl (new);
  555.         }
  556.       else
  557.         {
  558.           /* Since the type is OLD's, make OLD's size go with.  */
  559.           DECL_SIZE (new) = DECL_SIZE (old);
  560.           DECL_SIZE_UNIT (new) = DECL_SIZE_UNIT (old);
  561.         }
  562.  
  563.       /* Merge the initialization information.  */
  564.       if (DECL_INITIAL (new) == 0)
  565.         DECL_INITIAL (new) = DECL_INITIAL (old);
  566.       /* Keep the old rtl since we can safely use it.  */
  567.       DECL_RTL (new) = DECL_RTL (old);
  568.     }
  569.       /* If cannot merge, then use the new type
  570.      and discard the old rtl.  */
  571.       else
  572.     TREE_TYPE (old) = TREE_TYPE (new);
  573.  
  574.       /* Merge the storage class information.  */
  575.       if (TREE_EXTERNAL (new))
  576.     {
  577.       TREE_STATIC (new) = TREE_STATIC (old);
  578.       TREE_PUBLIC (new) = TREE_PUBLIC (old);
  579.       TREE_EXTERNAL (new) = TREE_EXTERNAL (old);
  580.     }
  581.       else
  582.     {
  583.       TREE_STATIC (old) = TREE_STATIC (new);
  584.       TREE_EXTERNAL (old) = 0;
  585.       TREE_PUBLIC (old) = TREE_PUBLIC (new);
  586.     }
  587.       /* If either decl says `inline', this fn is inline,
  588.      unless its definition was passed already.  */
  589.       if (TREE_INLINE (new) && DECL_INITIAL (old) == 0)
  590.     TREE_INLINE (old) = 1;
  591.  
  592.       bcopy ((char *) new + sizeof (struct tree_common),
  593.          (char *) old + sizeof (struct tree_common),
  594.          sizeof (struct tree_decl) - sizeof (struct tree_common));
  595.       return 1;
  596.     }
  597.  
  598.   /* New decl is completely inconsistent with the old one =>
  599.      tell caller to replace the old one.  */
  600.   return 0;
  601. }
  602.  
  603. /* Record a decl-node X as belonging to the current lexical scope.
  604.    Check for errors (such as an incompatible declaration for the same
  605.    name already seen in the same scope).
  606.  
  607.    Returns either X or an old decl for the same name.
  608.    If an old decl is returned, it may have been smashed
  609.    to agree with what X says.  */
  610.  
  611. tree
  612. pushdecl (x)
  613.      tree x;
  614. {
  615.   register tree t;
  616.   register tree name = DECL_NAME (x);
  617.   register struct binding_level *b = current_binding_level;
  618.  
  619.   if (name)
  620.     {
  621.       t = lookup_name_current_level (name);
  622.       if (t != 0 && t == error_mark_node)
  623.     {
  624.       t = 0;
  625.       error_with_decl (x, "`%s' used prior to declaration");
  626.     }
  627.  
  628.       if (t && duplicate_decls (x, t))
  629.     return t;
  630.  
  631.       /* If declaring a type as a typedef, and the type has no known
  632.      typedef name, install this TYPE_DECL as its typedef name.  */
  633.       if (TREE_CODE (x) == TYPE_DECL)
  634.     if (TYPE_NAME (TREE_TYPE (x)) == 0)
  635.       TYPE_NAME (TREE_TYPE (x)) = x;
  636.  
  637.       /* In PCC-compatibility mode, extern decls of vars with no current decl
  638.      take effect at top level no matter where they are.  */
  639.       if (flag_traditional && TREE_EXTERNAL (x)
  640.       && lookup_name (name) == 0)
  641.     b = global_binding_level;
  642.  
  643.       /* This name is new in its binding level.
  644.      Install the new declaration and return it.  */
  645.       if (b == global_binding_level)
  646.     {
  647.       /* Install a global value.  */
  648.       
  649.       IDENTIFIER_GLOBAL_VALUE (name) = x;
  650.  
  651.       if (IDENTIFIER_IMPLICIT_DECL (name) != 0
  652.           /* If this real decl matches the implicit, don't complain.  */
  653.           && ! (TREE_CODE (x) == FUNCTION_DECL
  654.             && TREE_TYPE (TREE_TYPE (x)) == integer_type_node))
  655.         warning ("`%s' was previously implicitly declared to return `int'",
  656.              IDENTIFIER_POINTER (name));
  657.  
  658.       /* If this decl is `static' and an `extern' was seen previously,
  659.          that is erroneous.  */
  660.       if (TREE_PUBLIC (name)
  661.           && ! TREE_PUBLIC (x) && ! TREE_EXTERNAL (x))
  662.         {
  663.           if (IDENTIFIER_IMPLICIT_DECL (name))
  664.         warning ("`%s' was declared implicitly `extern' and later `static'",
  665.              IDENTIFIER_POINTER (name));
  666.           else
  667.         warning ("`%s' was declared `extern' and later `static'",
  668.              IDENTIFIER_POINTER (name));
  669.         }
  670.     }
  671.       else
  672.     {
  673.       /* Here to install a non-global value.  */
  674.       tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
  675.       IDENTIFIER_LOCAL_VALUE (name) = x;
  676.  
  677.       /* If this is an extern function declaration, see if we
  678.          have a global definition for the function.  */
  679.       if (oldlocal == 0
  680.           && IDENTIFIER_GLOBAL_VALUE (name)
  681.           && TREE_CODE (x) == FUNCTION_DECL
  682.           && TREE_CODE (IDENTIFIER_GLOBAL_VALUE (name)) == FUNCTION_DECL
  683.           && TREE_INLINE (IDENTIFIER_GLOBAL_VALUE (name)))
  684.         {
  685.           /* We have one.  Their types must agree.  */
  686.           if (! comptypes (TREE_TYPE (x),
  687.                    TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (name))))
  688.         warning_with_decl (x, "local declaration of `%s' doesn't match global one");
  689.           /* If the global one is inline, make the local one inline.  */
  690.           else if (TREE_INLINE (IDENTIFIER_GLOBAL_VALUE (name)))
  691.         IDENTIFIER_LOCAL_VALUE (name) = IDENTIFIER_GLOBAL_VALUE (name);
  692.         }
  693.       /* If we have a local external declaration,
  694.          and no file-scope declaration has yet been seen,
  695.          then if we later have a file-scope decl it may not be static.  */
  696.       if (oldlocal == 0
  697.           && IDENTIFIER_GLOBAL_VALUE (name) == 0
  698.           && TREE_EXTERNAL (x))
  699.         {
  700.           TREE_PUBLIC (name) = 1;
  701.         }
  702.       /* Warn if shadowing an argument.  */
  703.       if (oldlocal != 0
  704.           && TREE_CODE (oldlocal) == PARM_DECL
  705.           && current_binding_level->level_chain->parm_flag)
  706.         warning ("shadowing parameter `%s' with a local variable",
  707.              IDENTIFIER_POINTER (name));
  708.       /* If storing a local value, there may already be one (inherited).
  709.          If so, record it for restoration when this binding level ends.  */
  710.       if (oldlocal != 0)
  711.         b->shadowed
  712.           = tree_cons (name, oldlocal,
  713.                b->shadowed);
  714.     }
  715.  
  716.       /* Keep count of variables in this level with incomplete type.  */
  717.       if (TYPE_SIZE (TREE_TYPE (x)) == 0)
  718.     ++b->n_incomplete;
  719.     }
  720.  
  721.   /* Put decls on list in reverse order.
  722.      We will reverse them later if necessary.  */
  723.   TREE_CHAIN (x) = b->names;
  724.   b->names = x;
  725.  
  726.   return x;
  727. }
  728.  
  729. /* Generate an implicit declaration for identifier FUNCTIONID
  730.    as a function of type int ().  Print a warning if appropriate.  */
  731.  
  732. tree
  733. implicitly_declare (functionid)
  734.      tree functionid;
  735. {
  736.   register tree decl;
  737.  
  738.   /* Save the decl permanently so we can warn if definition follows.  */
  739.   if (flag_traditional)
  740.     end_temporary_allocation ();
  741.  
  742.   /* We used to reuse an old implicit decl here,
  743.      but this loses with inline functions because it can clobber
  744.      the saved decl chains.  */
  745. /*  if (IDENTIFIER_IMPLICIT_DECL (functionid) != 0)
  746.     decl = IDENTIFIER_IMPLICIT_DECL (functionid);
  747.   else  */
  748.     decl = build_decl (FUNCTION_DECL, functionid, default_function_type);
  749.  
  750.   TREE_EXTERNAL (decl) = 1;
  751.   TREE_PUBLIC (decl) = 1;
  752.  
  753.   /* ANSI standard says implicit declarations are in the innermost block.
  754.      So we record the decl in the standard fashion.
  755.      If flag_traditional is set, pushdecl does it top-level.  */
  756.   pushdecl (decl);
  757.   rest_of_decl_compilation (decl, 0, 0, 0);
  758.  
  759.   if (warn_implicit
  760.       /* Only one warning per identifier.  */
  761.       && IDENTIFIER_IMPLICIT_DECL (functionid) == 0)
  762.     warning ("implicit declaration of function `%s'",
  763.          IDENTIFIER_POINTER (functionid));
  764.  
  765.   IDENTIFIER_IMPLICIT_DECL (functionid) = decl;
  766.  
  767.   if (flag_traditional)
  768.     resume_temporary_allocation ();
  769.  
  770.   return decl;
  771. }
  772.  
  773. /* Return zero if the declaration NEW is valid
  774.    when the declaration OLD (assumed to be for the same name)
  775.    has already been seen.
  776.    Otherwise return an error message format string with a %s
  777.    where the identifier should go.  */
  778.  
  779. static char *
  780. redeclaration_error_message (new, old)
  781.      tree new, old;
  782. {
  783.   if (TREE_CODE (new) == TYPE_DECL)
  784.     return "redefinition of `%s'";
  785.   else if (TREE_CODE (new) == FUNCTION_DECL)
  786.     {
  787.       /* Declarations of functions can insist on internal linkage
  788.      but they can't be inconsistent with internal linkage,
  789.      so there can be no error on that account.
  790.      However defining the same name twice is no good.  */
  791.       if (DECL_INITIAL (old) != 0 && DECL_INITIAL (new) != 0)
  792.     return "redefinition of `%s'";
  793.       return 0;
  794.     }
  795.   else if (current_binding_level == global_binding_level)
  796.     {
  797.       /* Objects declared at top level:  */
  798.       /* If at least one is a reference, it's ok.  */
  799.       if (TREE_EXTERNAL (new) || TREE_EXTERNAL (old))
  800.     return 0;
  801.       /* Reject two definitions.  */
  802.       if (DECL_INITIAL (old) != 0 && DECL_INITIAL (new) != 0)
  803.     return "redefinition of `%s'";
  804.       /* Now we have two tentative defs, or one tentative and one real def.  */
  805.       /* Insist that the linkage match.  */
  806.       if (TREE_PUBLIC (old) != TREE_PUBLIC (new))
  807.     return "conflicting declarations of `%s'";
  808.       return 0;
  809.     }
  810.   else
  811.     {
  812.       /* Objects declared with block scope:  */
  813.       /* Reject two definitions, and reject a definition
  814.      together with an external reference.  */
  815.        if (!(TREE_EXTERNAL (new) && TREE_EXTERNAL (old)))
  816.     return "redeclaration of `%s'";
  817.       return 0;
  818.     }
  819. }
  820.  
  821. /* Get the LABEL_DECL corresponding to identifier ID as a label.
  822.    Create one if none exists so far for the current function.
  823.    This function is called for both label definitions and label references.  */
  824.  
  825. tree
  826. lookup_label (id)
  827.      tree id;
  828. {
  829.   register tree decl = IDENTIFIER_LABEL_VALUE (id);
  830.  
  831.   if (decl != 0)
  832.     return decl;
  833.  
  834.   decl = build_decl (LABEL_DECL, id, NULL_TREE);
  835.   DECL_MODE (decl) = VOIDmode;
  836.   /* Mark that the label's definition has not been seen.  */
  837.   DECL_SOURCE_LINE (decl) = 0;
  838.  
  839.   IDENTIFIER_LABEL_VALUE (id) = decl;
  840.  
  841.   named_labels
  842.     = tree_cons (NULL_TREE, decl, named_labels);
  843.  
  844.   return decl;
  845. }
  846.  
  847. /* Define a label, specifying the location in the source file.
  848.    Return the LABEL_DECL node for the label, if the definition is valid.
  849.    Otherwise return 0.  */
  850.  
  851. tree
  852. define_label (filename, line, name)
  853.      char *filename;
  854.      int line;
  855.      tree name;
  856. {
  857.   tree decl = lookup_label (name);
  858.   if (DECL_SOURCE_LINE (decl) != 0)
  859.     {
  860.       error_with_decl (decl, "duplicate label `%s'");
  861.       return 0;
  862.     }
  863.   else
  864.     {
  865.       /* Mark label as having been defined.  */
  866.       DECL_SOURCE_FILE (decl) = filename;
  867.       DECL_SOURCE_LINE (decl) = line;
  868.       return decl;
  869.     }
  870. }
  871.  
  872. /* Return the list of declarations of the current level.
  873.    Note that this list is in reverse order unless/until
  874.    you nreverse it; and when you do nreverse it, you must
  875.    store the result back using `storedecls' or you will lose.  */
  876.  
  877. tree
  878. getdecls ()
  879. {
  880.   return current_binding_level->names;
  881. }
  882.  
  883. /* Return the list of type-tags (for structs, etc) of the current level.  */
  884.  
  885. tree
  886. gettags ()
  887. {
  888.   return current_binding_level->tags;
  889. }
  890.  
  891. /* Store the list of declarations of the current level.
  892.    This is done for the parameter declarations of a function being defined,
  893.    after they are modified in the light of any missing parameters.  */
  894.  
  895. static void
  896. storedecls (decls)
  897.      tree decls;
  898. {
  899.   current_binding_level->names = decls;
  900. }
  901.  
  902. /* Similarly, store the list of tags of the current level.  */
  903.  
  904. static void
  905. storetags (tags)
  906.      tree tags;
  907. {
  908.   current_binding_level->tags = tags;
  909. }
  910.  
  911. /* Given NAME, an IDENTIFIER_NODE,
  912.    return the structure (or union or enum) definition for that name.
  913.    Searches binding levels from BINDING_LEVEL up to the global level.
  914.    If THISLEVEL_ONLY is nonzero, searches only the specified context
  915.    (but skips any tag-transparent contexts to find one that is
  916.    meaningful for tags).
  917.    FORM says which kind of type the caller wants;
  918.    it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE.
  919.    If the wrong kind of type is found, an error is reported.  */
  920.  
  921. static tree
  922. lookup_tag (form, name, binding_level, thislevel_only)
  923.      enum tree_code form;
  924.      struct binding_level *binding_level;
  925.      tree name;
  926.      int thislevel_only;
  927. {
  928.   register struct binding_level *level;
  929.  
  930.   for (level = binding_level; level; level = level->level_chain)
  931.     {
  932.       register tree tail;
  933.       for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
  934.     {
  935.       if (TREE_PURPOSE (tail) == name)
  936.         {
  937.           if (TREE_CODE (TREE_VALUE (tail)) != form)
  938.         {
  939.           /* Definition isn't the kind we were looking for.  */
  940.           error ("`%s' defined as wrong kind of tag",
  941.              IDENTIFIER_POINTER (name));
  942.         }
  943.           return TREE_VALUE (tail);
  944.         }
  945.     }
  946.       if (thislevel_only && ! level->tag_transparent)
  947.     return NULL_TREE;
  948.     }
  949.   return NULL_TREE;
  950. }
  951.  
  952. /* Given a type, find the tag that was defined for it and return the tag name.
  953.    Otherwise return 0.  However, the value can never be 0
  954.    in the cases in which this is used.  */
  955.  
  956. static tree
  957. lookup_tag_reverse (type)
  958.      tree type;
  959. {
  960.   register struct binding_level *level;
  961.  
  962.   for (level = current_binding_level; level; level = level->level_chain)
  963.     {
  964.       register tree tail;
  965.       for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
  966.     {
  967.       if (TREE_VALUE (tail) == type)
  968.         return TREE_PURPOSE (tail);
  969.     }
  970.     }
  971.   return NULL_TREE;
  972. }
  973.  
  974. /* Look up NAME in the current binding level and its superiors
  975.    in the namespace of variables, functions and typedefs.
  976.    Return a ..._DECL node of some kind representing its definition,
  977.    or return 0 if it is undefined.  */
  978.  
  979. tree
  980. lookup_name (name)
  981.      tree name;
  982. {
  983.   register tree val;
  984.   if (current_binding_level != global_binding_level
  985.       && IDENTIFIER_LOCAL_VALUE (name))
  986.     val = IDENTIFIER_LOCAL_VALUE (name);
  987.   else
  988.     val = IDENTIFIER_GLOBAL_VALUE (name);
  989.   if (val && TREE_TYPE (val) == error_mark_node)
  990.     return error_mark_node;
  991.   return val;
  992. }
  993.  
  994. /* Similar to `lookup_name' but look only at current binding level.  */
  995.  
  996. static tree
  997. lookup_name_current_level (name)
  998.      tree name;
  999. {
  1000.   register tree t;
  1001.  
  1002.   if (current_binding_level == global_binding_level)
  1003.     return IDENTIFIER_GLOBAL_VALUE (name);
  1004.  
  1005.   if (IDENTIFIER_LOCAL_VALUE (name) == 0)
  1006.     return 0;
  1007.  
  1008.   for (t = current_binding_level->names; t; t = TREE_CHAIN (t))
  1009.     if (DECL_NAME (t) == name)
  1010.       break;
  1011.  
  1012.   return t;
  1013. }
  1014.  
  1015. /* Create the predefined scalar types of C,
  1016.    and some nodes representing standard constants (0, 1, (void *)0).
  1017.    Initialize the global binding level.
  1018.    Make definitions for built-in primitive functions.  */
  1019.  
  1020. void
  1021. init_decl_processing ()
  1022. {
  1023.   register tree endlink;
  1024.  
  1025.   current_function_decl = NULL;
  1026.   named_labels = NULL;
  1027.   current_binding_level = NULL_BINDING_LEVEL;
  1028.   free_binding_level = NULL_BINDING_LEVEL;
  1029.   pushlevel (0);    /* make the binding_level structure for global names */
  1030.   global_binding_level = current_binding_level;
  1031.  
  1032.   value_identifier = get_identifier ("<value>");
  1033.  
  1034.   /* Define `int' and `char' first so that dbx will output them first.  */
  1035.  
  1036. #ifdef INT_TYPE_SIZE
  1037.   integer_type_node = make_signed_type (INT_TYPE_SIZE);
  1038. #else
  1039.   integer_type_node = make_signed_type (BITS_PER_WORD);
  1040. #endif
  1041.   pushdecl (build_decl (TYPE_DECL, ridpointers[(int) RID_INT],
  1042.             integer_type_node));
  1043.  
  1044.   /* Define `char', which is like either `signed char' or `unsigned char'
  1045.      but not the same as either.  */
  1046.  
  1047.   char_type_node =
  1048.     (flag_signed_char
  1049.      ? make_signed_type (BITS_PER_UNIT)
  1050.      : make_unsigned_type (BITS_PER_UNIT));
  1051.   pushdecl (build_decl (TYPE_DECL, get_identifier ("char"),
  1052.             char_type_node));
  1053.  
  1054. #ifdef INT_TYPE_SIZE
  1055.   unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);
  1056. #else
  1057.   unsigned_type_node = make_unsigned_type (BITS_PER_WORD);
  1058. #endif
  1059.   pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned int"),
  1060.             unsigned_type_node));
  1061.  
  1062.   long_unsigned_type_node = make_unsigned_type (BITS_PER_WORD);
  1063.   pushdecl (build_decl (TYPE_DECL, get_identifier ("long unsigned int"),
  1064.             long_unsigned_type_node));
  1065.  
  1066.   /* `unsigned long' or `unsigned int' is the type for sizeof.  */
  1067. #ifdef INT_TYPE_SIZE
  1068.   if (INT_TYPE_SIZE != BITS_PER_WORD)
  1069.     sizetype = long_unsigned_type_node;
  1070.   else
  1071.     sizetype = unsigned_type_node;
  1072. #else
  1073.   sizetype = unsigned_type_node;
  1074. #endif
  1075.  
  1076.   TREE_TYPE (TYPE_SIZE (integer_type_node)) = sizetype;
  1077.   TREE_TYPE (TYPE_SIZE (char_type_node)) = sizetype;
  1078.   TREE_TYPE (TYPE_SIZE (unsigned_type_node)) = sizetype;
  1079.   TREE_TYPE (TYPE_SIZE (long_unsigned_type_node)) = sizetype;
  1080.  
  1081.   error_mark_node = make_node (ERROR_MARK);
  1082.   TREE_TYPE (error_mark_node) = error_mark_node;
  1083.  
  1084.   short_integer_type_node = make_signed_type (BITS_PER_UNIT * MIN (UNITS_PER_WORD / 2, 2));
  1085.   pushdecl (build_decl (TYPE_DECL, get_identifier ("short int"),
  1086.             short_integer_type_node));
  1087.  
  1088.   long_integer_type_node = make_signed_type (BITS_PER_WORD);
  1089.   pushdecl (build_decl (TYPE_DECL, get_identifier ("long int"),
  1090.             long_integer_type_node));
  1091.  
  1092.   long_long_integer_type_node = make_signed_type (2 * BITS_PER_WORD);
  1093.   pushdecl (build_decl (TYPE_DECL, get_identifier ("long long int"),
  1094.             long_long_integer_type_node));
  1095.  
  1096.   short_unsigned_type_node = make_unsigned_type (BITS_PER_UNIT * MIN (UNITS_PER_WORD / 2, 2));
  1097.   pushdecl (build_decl (TYPE_DECL, get_identifier ("short unsigned int"),
  1098.             short_unsigned_type_node));
  1099.  
  1100.   long_long_unsigned_type_node = make_unsigned_type (2 * BITS_PER_WORD);
  1101.   pushdecl (build_decl (TYPE_DECL, get_identifier ("long long unsigned int"),
  1102.             long_long_unsigned_type_node));
  1103.  
  1104.   /* Define both `signed char' and `unsigned char'.  */
  1105.   signed_char_type_node = make_signed_type (BITS_PER_UNIT);
  1106.   pushdecl (build_decl (TYPE_DECL, get_identifier ("signed char"),
  1107.             signed_char_type_node));
  1108.  
  1109.   unsigned_char_type_node = make_unsigned_type (BITS_PER_UNIT);
  1110.   pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned char"),
  1111.             unsigned_char_type_node));
  1112.  
  1113.   float_type_node = make_node (REAL_TYPE);
  1114.   TYPE_PRECISION (float_type_node) = BITS_PER_WORD;
  1115.   pushdecl (build_decl (TYPE_DECL, ridpointers[(int) RID_FLOAT],
  1116.             float_type_node));
  1117.   layout_type (float_type_node);
  1118.  
  1119.   double_type_node = make_node (REAL_TYPE);
  1120.   TYPE_PRECISION (double_type_node) = 2 * BITS_PER_WORD;
  1121.   pushdecl (build_decl (TYPE_DECL, ridpointers[(int) RID_DOUBLE],
  1122.             double_type_node));
  1123.   layout_type (double_type_node);
  1124.  
  1125.   long_double_type_node = make_node (REAL_TYPE);
  1126.   TYPE_PRECISION (long_double_type_node) = 2 * BITS_PER_WORD;
  1127.   pushdecl (build_decl (TYPE_DECL, get_identifier ("long double"),
  1128.             long_double_type_node));
  1129.   layout_type (long_double_type_node);
  1130.  
  1131.   integer_zero_node = build_int_2 (0, 0);
  1132.   TREE_TYPE (integer_zero_node) = integer_type_node;
  1133.   integer_one_node = build_int_2 (1, 0);
  1134.   TREE_TYPE (integer_one_node) = integer_type_node;
  1135.  
  1136.   size_zero_node = build_int_2 (0, 0);
  1137.   TREE_TYPE (size_zero_node) = sizetype;
  1138.   size_one_node = build_int_2 (1, 0);
  1139.   TREE_TYPE (size_one_node) = sizetype;
  1140.  
  1141.   void_type_node = make_node (VOID_TYPE);
  1142.   pushdecl (build_decl (TYPE_DECL,
  1143.             ridpointers[(int) RID_VOID], void_type_node));
  1144.   layout_type (void_type_node);    /* Uses integer_zero_node */
  1145.  
  1146.   null_pointer_node = build_int_2 (0, 0);
  1147.   TREE_TYPE (null_pointer_node) = build_pointer_type (void_type_node);
  1148.   layout_type (TREE_TYPE (null_pointer_node));
  1149.  
  1150.   string_type_node = build_pointer_type (char_type_node);
  1151.  
  1152.   /* make a type for arrays of 256 characters.
  1153.      256 is picked randomly because we have a type for integers from 0 to 255.
  1154.      With luck nothing will ever really depend on the length of this
  1155.      array type.  */
  1156.   char_array_type_node
  1157.     = build_array_type (char_type_node, unsigned_char_type_node);
  1158.   /* Likewise for arrays of ints.  */
  1159.   int_array_type_node
  1160.     = build_array_type (integer_type_node, unsigned_char_type_node);
  1161.  
  1162.   default_function_type
  1163.     = build_function_type (integer_type_node, NULL_TREE);
  1164.  
  1165.   ptr_type_node = build_pointer_type (void_type_node);
  1166.   endlink = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
  1167.  
  1168.   double_ftype_double
  1169.     = build_function_type (double_type_node,
  1170.                tree_cons (NULL_TREE, double_type_node, endlink));
  1171.  
  1172.   double_ftype_double_double
  1173.     = build_function_type (double_type_node,
  1174.                tree_cons (NULL_TREE, double_type_node,
  1175.                       tree_cons (NULL_TREE,
  1176.                          double_type_node, endlink)));
  1177.  
  1178.   int_ftype_int
  1179.     = build_function_type (integer_type_node,
  1180.                tree_cons (NULL_TREE, integer_type_node, endlink));
  1181.  
  1182.   long_ftype_long
  1183.     = build_function_type (long_integer_type_node,
  1184.                tree_cons (NULL_TREE,
  1185.                       long_integer_type_node, endlink));
  1186.  
  1187.   void_ftype_ptr_ptr_int
  1188.     = build_function_type (void_type_node,
  1189.                tree_cons (NULL_TREE, ptr_type_node,
  1190.                       tree_cons (NULL_TREE, ptr_type_node,
  1191.                          tree_cons (NULL_TREE,
  1192.                                 integer_type_node,
  1193.                                 endlink))));
  1194.  
  1195.   int_ftype_ptr_ptr_int
  1196.     = build_function_type (integer_type_node,
  1197.                tree_cons (NULL_TREE, ptr_type_node,
  1198.                       tree_cons (NULL_TREE, ptr_type_node,
  1199.                          tree_cons (NULL_TREE,
  1200.                                 integer_type_node,
  1201.                                 endlink))));
  1202.  
  1203.   void_ftype_ptr_int_int
  1204.     = build_function_type (void_type_node,
  1205.                tree_cons (NULL_TREE, ptr_type_node,
  1206.                       tree_cons (NULL_TREE, integer_type_node,
  1207.                          tree_cons (NULL_TREE,
  1208.                                 integer_type_node,
  1209.                                 endlink))));
  1210.  
  1211.   builtin_function ("__builtin_alloca",
  1212.             build_function_type (ptr_type_node,
  1213.                      tree_cons (NULL_TREE,
  1214.                             integer_type_node,
  1215.                             endlink)),
  1216.             BUILT_IN_ALLOCA);
  1217.  
  1218.   builtin_function ("__builtin_abs", int_ftype_int, BUILT_IN_ABS);
  1219.   builtin_function ("__builtin_fabs", double_ftype_double, BUILT_IN_FABS);
  1220.   builtin_function ("__builtin_labs", long_ftype_long, BUILT_IN_LABS);
  1221.   builtin_function ("__builtin_ffs", int_ftype_int, BUILT_IN_FFS);
  1222. /*  builtin_function ("__builtin_div", default_ftype, BUILT_IN_DIV);
  1223.   builtin_function ("__builtin_ldiv", default_ftype, BUILT_IN_LDIV); */
  1224.   builtin_function ("__builtin_ffloor", double_ftype_double, BUILT_IN_FFLOOR);
  1225.   builtin_function ("__builtin_fceil", double_ftype_double, BUILT_IN_FCEIL);
  1226.   builtin_function ("__builtin_fmod", double_ftype_double_double, BUILT_IN_FMOD);
  1227.   builtin_function ("__builtin_frem", double_ftype_double_double, BUILT_IN_FREM);
  1228.   builtin_function ("__builtin_memcpy", void_ftype_ptr_ptr_int, BUILT_IN_MEMCPY);
  1229.   builtin_function ("__builtin_memcmp", int_ftype_ptr_ptr_int, BUILT_IN_MEMCMP);
  1230.   builtin_function ("__builtin_memset", void_ftype_ptr_int_int, BUILT_IN_MEMSET);
  1231.   builtin_function ("__builtin_fsqrt", double_ftype_double, BUILT_IN_FSQRT);
  1232.   builtin_function ("__builtin_getexp", double_ftype_double, BUILT_IN_GETEXP);
  1233.   builtin_function ("__builtin_getman", double_ftype_double, BUILT_IN_GETMAN);
  1234. }
  1235.  
  1236. /* Make a definition for a builtin function named NAME and whose data type
  1237.    is TYPE.  TYPE should be a function type with argument types.
  1238.    FUNCTION_CODE tells later passes how to compile calls to this function.
  1239.    See tree.h for its possible values.  */
  1240.  
  1241. static void
  1242. builtin_function (name, type, function_code)
  1243.      char *name;
  1244.      tree type;
  1245.      enum built_in_function function_code;
  1246. {
  1247.   tree decl = build_decl (FUNCTION_DECL, get_identifier (name), type);
  1248.   TREE_EXTERNAL (decl) = 1;
  1249.   TREE_PUBLIC (decl) = 1;
  1250.   make_function_rtl (decl);
  1251.   pushdecl (decl);
  1252.   DECL_SET_FUNCTION_CODE (decl, function_code);
  1253. }
  1254.  
  1255. /* Called when a declaration is seen that contains no names to declare.
  1256.    If its type is a reference to a structure, union or enum inherited
  1257.    from a containing scope, shadow that tag name for the current scope
  1258.    with a forward reference.
  1259.    If its type defines a new named structure or union
  1260.    or defines an enum, it is valid but we need not do anything here.
  1261.    Otherwise, it is an error.  */
  1262.  
  1263. void
  1264. shadow_tag (declspecs)
  1265.      tree declspecs;
  1266. {
  1267.   register tree link;
  1268.  
  1269.   for (link = declspecs; link; link = TREE_CHAIN (link))
  1270.     {
  1271.       register tree value = TREE_VALUE (link);
  1272.       register enum tree_code code = TREE_CODE (value);
  1273.       if ((code == RECORD_TYPE || code == UNION_TYPE || code == ENUMERAL_TYPE)
  1274.       && TYPE_SIZE (value) != 0)
  1275.     {
  1276.       register tree name = lookup_tag_reverse (value);
  1277.       register tree t = lookup_tag (code, name, current_binding_level, 1);
  1278.       if (t == 0)
  1279.         {
  1280.           t = make_node (code);
  1281.           pushtag (name, t);
  1282.           return;
  1283.         }
  1284.       if (name != 0 || code == ENUMERAL_TYPE)
  1285.         return;
  1286.     }
  1287.     }
  1288.   warning ("empty declaration");
  1289. }
  1290.  
  1291. /* Decode a "typename", such as "int **", returning a ..._TYPE node.  */
  1292.  
  1293. tree
  1294. groktypename (typename)
  1295.      tree typename;
  1296. {
  1297.   if (TREE_CODE (typename) != TREE_LIST)
  1298.     return typename;
  1299.   return grokdeclarator (TREE_VALUE (typename),
  1300.              TREE_PURPOSE (typename),
  1301.              TYPENAME, 0);
  1302. }
  1303.  
  1304. /* Decode a declarator in an ordinary declaration or data definition.
  1305.    This is called as soon as the type information and variable name
  1306.    have been parsed, before parsing the initializer if any.
  1307.    Here we create the ..._DECL node, fill in its type,
  1308.    and put it on the list of decls for the current context.
  1309.    The ..._DECL node is returned as the value.
  1310.  
  1311.    Exception: for arrays where the length is not specified,
  1312.    the type is left null, to be filled in by `finish_decl'.
  1313.  
  1314.    Function definitions do not come here; they go to start_function
  1315.    instead.  However, external and forward declarations of functions
  1316.    do go through here.  Structure field declarations are done by
  1317.    grokfield and not through here.  */
  1318.  
  1319. /* Set this to zero to debug not using the temporary obstack
  1320.    to parse initializers.  */
  1321. int debug_temp_inits = 1;
  1322.  
  1323. tree
  1324. start_decl (declarator, declspecs, initialized)
  1325.      tree declspecs, declarator;
  1326.      int initialized;
  1327. {
  1328.   register tree decl = grokdeclarator (declarator, declspecs,
  1329.                        NORMAL, initialized);
  1330.   register tree tem;
  1331.   int init_written = initialized;
  1332.  
  1333.   if (initialized)
  1334.     /* Is it valid for this decl to have an initializer at all?
  1335.        If not, set INITIALIZED to zero, which will indirectly
  1336.        tell `finish_decl' to ignore the initializer once it is parsed.  */
  1337.     switch (TREE_CODE (decl))
  1338.       {
  1339.       case TYPE_DECL:
  1340.     /* typedef foo = bar  means give foo the same type as bar.
  1341.        We haven't parsed bar yet, so `finish_decl' will fix that up.
  1342.        Any other case of an initialization in a TYPE_DECL is an error.  */
  1343.     if (pedantic || list_length (declspecs) > 1)
  1344.       {
  1345.         error ("typedef `%s' is initialized",
  1346.            IDENTIFIER_POINTER (DECL_NAME (decl)));
  1347.         initialized = 0;
  1348.       }
  1349.     break;
  1350.  
  1351.       case FUNCTION_DECL:
  1352.     error ("function `%s' is initialized like a variable",
  1353.            IDENTIFIER_POINTER (DECL_NAME (decl)));
  1354.     initialized = 0;
  1355.     break;
  1356.  
  1357.       default:
  1358.     /* Don't allow initializations for incomplete types
  1359.        except for arrays which might be completed by the initialization.  */
  1360.     if (TYPE_SIZE (TREE_TYPE (decl)) != 0)
  1361.       ;            /* A complete type is ok.  */
  1362.     else if (TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE)
  1363.       {
  1364.         error ("variable `%s' has initializer but incomplete type",
  1365.            IDENTIFIER_POINTER (DECL_NAME (decl)));
  1366.         initialized = 0;
  1367.       }
  1368.     else if (TYPE_SIZE (TREE_TYPE (TREE_TYPE (decl))) == 0)
  1369.       {
  1370.         error ("elements of array `%s' have incomplete type",
  1371.            IDENTIFIER_POINTER (DECL_NAME (decl)));
  1372.         initialized = 0;
  1373.       }
  1374.       }
  1375.  
  1376.   if (initialized)
  1377.     {
  1378.       if (current_binding_level != global_binding_level
  1379.       && TREE_EXTERNAL (decl))
  1380.     warning ("declaration of `%s' has `extern' and is initialized",
  1381.          IDENTIFIER_POINTER (DECL_NAME (decl)));
  1382.       TREE_EXTERNAL (decl) = 0;
  1383.       if (current_binding_level == global_binding_level)
  1384.     TREE_STATIC (decl) = 1;
  1385.  
  1386.       /* Tell `pushdecl' this is an initialized decl
  1387.      even though we don't yet have the initializer expression.
  1388.      Also tell `finish_decl' it may store the real initializer.  */
  1389.       DECL_INITIAL (decl) = error_mark_node;
  1390.     }
  1391.  
  1392.   /* Add this decl to the current binding level.  */
  1393.   tem = pushdecl (decl);
  1394.  
  1395.   if (init_written)
  1396.     {
  1397.       /* When parsing and digesting the initializer,
  1398.      use temporary storage.  Do this even if we will ignore the value.  */
  1399.       if (current_binding_level == global_binding_level && debug_temp_inits)
  1400.     temporary_allocation ();
  1401.     }
  1402.  
  1403.   return tem;
  1404. }
  1405.  
  1406. /* Finish processing of a declaration;
  1407.    install its line number and initial value.
  1408.    If the length of an array type is not known before,
  1409.    it must be determined now, from the initial value, or it is an error.  */
  1410.  
  1411. void
  1412. finish_decl (decl, init, asmspec)
  1413.      tree decl, init;
  1414.      tree asmspec;
  1415. {
  1416.   register tree type = TREE_TYPE (decl);
  1417.   int init_written = init != 0;
  1418.  
  1419.   /* If `start_decl' didn't like having an initialization, ignore it now.  */
  1420.  
  1421.   if (init != 0 && DECL_INITIAL (decl) == 0)
  1422.     init = 0;
  1423.  
  1424.   if (init)
  1425.     {
  1426.       if (TREE_CODE (decl) != TYPE_DECL)
  1427.     store_init_value (decl, init);
  1428.       else
  1429.     {
  1430.       /* typedef foo = bar; store the type of bar as the type of foo.  */
  1431.       TREE_TYPE (decl) = TREE_TYPE (init);
  1432.       DECL_INITIAL (decl) = init = 0;
  1433.     }
  1434.     }
  1435.  
  1436.   /* For top-level declaration, the initial value was read in
  1437.      the temporary obstack.  MAXINDEX, rtl, etc. to be made below
  1438.      must go in the permanent obstack; but don't discard the
  1439.      temporary data yet.  */
  1440.  
  1441.   if (current_binding_level == global_binding_level
  1442.       && allocation_temporary_p ())
  1443.     end_temporary_allocation ();
  1444.  
  1445.   /* Deduce size of array from initialization, if not already known */
  1446.  
  1447.   if (TREE_CODE (type) == ARRAY_TYPE
  1448.       && TYPE_DOMAIN (type) == 0
  1449.       && TREE_CODE (decl) != TYPE_DECL)
  1450.     {
  1451.       int do_default = ! ((!pedantic && TREE_STATIC (decl))
  1452.               || TREE_EXTERNAL (decl));
  1453.       int failure
  1454.     = complete_array_type (type, DECL_INITIAL (decl), do_default);
  1455.  
  1456.       if (failure == 1)
  1457.     error_with_decl (decl, "initializer fails to determine size of `%s'");
  1458.  
  1459.       if (failure == 2)
  1460.     {
  1461.       if (do_default)
  1462.         error_with_decl (decl, "array size missing in `%s'");
  1463.       else if (!pedantic && TREE_STATIC (decl))
  1464.         TREE_EXTERNAL (decl) = 1;
  1465.     }
  1466.  
  1467.       if (pedantic && TYPE_DOMAIN (type) != 0
  1468.       && tree_int_cst_lt (TYPE_MAX_VALUE (TYPE_DOMAIN (type)),
  1469.                   integer_zero_node))
  1470.     error_with_decl (decl, "zero-size array `%s'");
  1471.  
  1472.       if (TREE_CODE (decl) != TYPE_DECL)
  1473.     layout_decl (decl, 0);
  1474.     }
  1475.  
  1476.   if (TREE_CODE (decl) == VAR_DECL)
  1477.     {
  1478.       if (TREE_STATIC (decl) && DECL_SIZE (decl) == 0)
  1479.     {
  1480.       /* A static variable with an incomplete type:
  1481.          that is an error if it is initialized or `static'.
  1482.          Otherwise, let it through, but if it is not `extern'
  1483.          then it may cause an error message later.  */
  1484.       if (! (TREE_PUBLIC (decl) && DECL_INITIAL (decl) == 0))
  1485.         error_with_decl (decl, "storage size of `%s' isn't known");
  1486.     }
  1487.       else if (!TREE_EXTERNAL (decl) && DECL_SIZE (decl) == 0)
  1488.     {
  1489.       /* An automatic variable with an incomplete type:
  1490.          that is an error.  */
  1491.       error_with_decl (decl, "storage size of `%s' isn't known");
  1492.       TREE_TYPE (decl) = error_mark_node;
  1493.     }
  1494.  
  1495.       if ((TREE_EXTERNAL (decl) || TREE_STATIC (decl))
  1496.       && DECL_SIZE (decl) != 0 && ! TREE_LITERAL (DECL_SIZE (decl)))
  1497.     error_with_decl (decl, "storage size of `%s' isn't constant");
  1498.     }
  1499.  
  1500.   /* Output the assembler code and/or RTL code for variables and functions,
  1501.      unless the type is an undefined structure or union.
  1502.      If not, it will get done when the type is completed.  */
  1503.  
  1504.   if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL)
  1505.     {
  1506.       if (flag_traditional && allocation_temporary_p ())
  1507.     {
  1508.       end_temporary_allocation ();
  1509.       rest_of_decl_compilation (decl, asmspec,
  1510.                     current_binding_level == global_binding_level,
  1511.                     0);
  1512.       resume_temporary_allocation ();
  1513.     }
  1514.       else
  1515.     rest_of_decl_compilation (decl, asmspec,
  1516.                   current_binding_level == global_binding_level,
  1517.                   0);
  1518.       if (TYPE_SIZE (TREE_TYPE (decl)) != 0
  1519.       || TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
  1520.     if (current_binding_level != global_binding_level)
  1521.       expand_decl (decl);
  1522.     }
  1523.  
  1524.   if (TREE_CODE (decl) == TYPE_DECL)
  1525.     rest_of_decl_compilation (decl, 0,
  1526.                   current_binding_level == global_binding_level,
  1527.                   0);
  1528.  
  1529.   /* Resume permanent allocation, if not within a function.  */
  1530.   if (allocation_temporary_p ()
  1531.       && current_binding_level == global_binding_level)
  1532.     permanent_allocation ();
  1533. }
  1534.  
  1535. /* Given a parsed parameter declaration,
  1536.    decode it into a PARM_DECL and push that on the current binding level.  */
  1537.  
  1538. void
  1539. push_parm_decl (parm)
  1540.      tree parm;
  1541. {
  1542.   register tree decl = grokdeclarator (TREE_VALUE (parm), TREE_PURPOSE (parm),
  1543.                        PARM, 0);
  1544.  
  1545.   /* Add this decl to the current binding level.  */
  1546.   finish_decl (pushdecl (decl), NULL_TREE, NULL_TREE);
  1547. }
  1548.  
  1549. /* Make TYPE a complete type based on INITIAL_VALUE.
  1550.    Return 0 if successful, 1 if INITIAL_VALUE can't be decyphered,
  1551.    2 if there was no information (in which case assume 1 if DO_DEFAULT).  */
  1552.  
  1553. int
  1554. complete_array_type (type, initial_value, do_default)
  1555.      tree type;
  1556.      tree initial_value;
  1557.      int do_default;
  1558. {
  1559.   register tree maxindex = NULL_TREE;
  1560.   int value = 0;
  1561.  
  1562.   if (initial_value)
  1563.     {
  1564.       /* Note MAXINDEX  is really the maximum index,
  1565.      one less than the size.  */
  1566.       if (TREE_CODE (initial_value) == STRING_CST)
  1567.     maxindex = build_int_2 (TREE_STRING_LENGTH (initial_value) - 1, 0);
  1568.       else if (TREE_CODE (initial_value) == CONSTRUCTOR)
  1569.     {
  1570.       register int nelts
  1571.         = list_length (CONSTRUCTOR_ELTS (initial_value));
  1572.       maxindex = build_int_2 (nelts - 1, 0);
  1573.     }
  1574.       else
  1575.     {
  1576.       /* Make an error message unless that happened already.  */
  1577.       if (initial_value != error_mark_node)
  1578.         value = 1;
  1579.  
  1580.       /* Prevent further error messages.  */
  1581.       maxindex = build_int_2 (1, 0);
  1582.     }
  1583.     }
  1584.  
  1585.   if (!maxindex)
  1586.     {
  1587.       if (do_default)
  1588.     maxindex = build_int_2 (1, 0);
  1589.       value = 2;
  1590.     }
  1591.  
  1592.   if (maxindex)
  1593.     {
  1594.       TYPE_DOMAIN (type) = make_index_type (maxindex);
  1595.       if (!TREE_TYPE (maxindex))
  1596.     TREE_TYPE (maxindex) = TYPE_DOMAIN (type);
  1597.     }
  1598.  
  1599.   /* Lay out the type now that we can get the real answer.  */
  1600.  
  1601.   layout_type (type);
  1602.  
  1603.   return value;
  1604. }
  1605.  
  1606. /* Given declspecs and a declarator,
  1607.    determine the name and type of the object declared.
  1608.    DECLSPECS is a chain of tree_list nodes whose value fields
  1609.     are the storage classes and type specifiers.
  1610.  
  1611.    DECL_CONTEXT says which syntactic context this declaration is in:
  1612.      NORMAL for most contexts.  Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
  1613.      FUNCDEF for a function definition.  Like NORMAL but a few different
  1614.       error messages in each case.  Return value may be zero meaning
  1615.       this definition is too screwy to try to parse.
  1616.      PARM for a parameter declaration (either within a function prototype
  1617.       or before a function body).  Make a PARM_DECL, or return void_type_node.
  1618.      TYPENAME if for a typename (in a cast or sizeof).
  1619.       Don't make a DECL node; just return the type.
  1620.      FIELD for a struct or union field; make a FIELD_DECL.
  1621.    INITIALIZED is 1 if the decl has an initializer.
  1622.  
  1623.    In the TYPENAME case, DECLARATOR is really an absolute declarator.
  1624.    It may also be so in the PARM case, for a prototype where the
  1625.    argument type is specified but not the name.
  1626.  
  1627.    This function is where the complicated C meanings of `static'
  1628.    and `extern' are intrepreted.  */
  1629.  
  1630. static tree
  1631. grokdeclarator (declarator, declspecs, decl_context, initialized)
  1632.      tree declspecs;
  1633.      tree declarator;
  1634.      enum decl_context decl_context;
  1635.      int initialized;
  1636. {
  1637.   int specbits = 0;
  1638.   tree spec;
  1639.   tree type = NULL_TREE;
  1640.   int longlong = 0;
  1641.   int constp;
  1642.   int volatilep;
  1643.   int inlinep;
  1644.   int explicit_int = 0;
  1645.   int explicit_char = 0;
  1646.   char *name;
  1647.   tree typedef_type = 0;
  1648.   int funcdef_flag = 0;
  1649.   int resume_temporary = 0;
  1650.   enum tree_code innermost_code = ERROR_MARK;
  1651.  
  1652.   if (decl_context == FUNCDEF)
  1653.     funcdef_flag = 1, decl_context = NORMAL;
  1654.  
  1655.   if (flag_traditional && allocation_temporary_p ())
  1656.     {
  1657.       resume_temporary = 1;
  1658.       end_temporary_allocation ();
  1659.     }
  1660.  
  1661.   /* Look inside a declarator for the name being declared
  1662.      and get it as a string, for an error message.  */
  1663.   {
  1664.     register tree decl = declarator;
  1665.     name = 0;
  1666.  
  1667.     while (decl)
  1668.       switch (TREE_CODE (decl))
  1669.     {
  1670.     case ARRAY_REF:
  1671.     case INDIRECT_REF:
  1672.     case CALL_EXPR:
  1673.       innermost_code = TREE_CODE (decl);
  1674.       decl = TREE_OPERAND (decl, 0);
  1675.       break;
  1676.  
  1677.     case IDENTIFIER_NODE:
  1678.       name = IDENTIFIER_POINTER (decl);
  1679.       decl = 0;
  1680.       break;
  1681.  
  1682.     default:
  1683.       abort ();
  1684.     }
  1685.     if (name == 0)
  1686.       name = "type name";
  1687.   }
  1688.  
  1689.   /* A function definition's declarator must have the form of
  1690.      a function declarator.  */
  1691.  
  1692.   if (funcdef_flag && innermost_code != CALL_EXPR)
  1693.     return 0;
  1694.  
  1695.   /* Anything declared one level down from the top level
  1696.      must be one of the parameters of a function
  1697.      (because the body is at least two levels down).  */
  1698.  
  1699.   if (decl_context == NORMAL
  1700.       && current_binding_level->level_chain == global_binding_level)
  1701.     decl_context = PARM;
  1702.  
  1703.   /* Look through the decl specs and record which ones appear.
  1704.      Some typespecs are defined as built-in typenames.
  1705.      Others, the ones that are modifiers of other types,
  1706.      are represented by bits in SPECBITS: set the bits for
  1707.      the modifiers that appear.  Storage class keywords are also in SPECBITS.
  1708.  
  1709.      If there is a typedef name or a type, store the type in TYPE.
  1710.      This includes builtin typedefs such as `int'.
  1711.  
  1712.      Set EXPLICIT_INT if the type is `int' or `char' and did not
  1713.      come from a user typedef.
  1714.  
  1715.      Set LONGLONG if `long' is mentioned twice.  */
  1716.  
  1717.   for (spec = declspecs; spec; spec = TREE_CHAIN (spec))
  1718.     {
  1719.       register int i;
  1720.       register tree id = TREE_VALUE (spec);
  1721.  
  1722.       if (id == ridpointers[(int) RID_INT])
  1723.     explicit_int = 1;
  1724.       if (id == ridpointers[(int) RID_CHAR])
  1725.     explicit_char = 1;
  1726.  
  1727.       if (TREE_CODE (id) == IDENTIFIER_NODE)
  1728.     for (i = (int) RID_FIRST_MODIFIER; i < (int) RID_MAX; i++)
  1729.       {
  1730.         if (ridpointers[i] == id)
  1731.           {
  1732.         if (i == (int) RID_LONG && specbits & (1<<i))
  1733.           {
  1734.             if (pedantic)
  1735.               warning ("duplicate `%s'", IDENTIFIER_POINTER (id));
  1736.             else
  1737.               longlong = 1;
  1738.           }
  1739.         else if (specbits & (1 << i))
  1740.           warning ("duplicate `%s'", IDENTIFIER_POINTER (id));
  1741.         specbits |= 1 << i;
  1742.         goto found;
  1743.           }
  1744.       }
  1745.       if (type)
  1746.     error ("two or more data types in declaration of `%s'", name);
  1747.       else if (TREE_CODE (id) == IDENTIFIER_NODE)
  1748.     {
  1749.       register tree t = lookup_name (id);
  1750.       if (!t || TREE_CODE (t) != TYPE_DECL)
  1751.         error ("`%s' fails to be a typedef or built in type",
  1752.            IDENTIFIER_POINTER (id));
  1753.       else type = TREE_TYPE (t);
  1754.     }
  1755.       else if (TREE_CODE (id) != ERROR_MARK)
  1756.     type = id;
  1757.  
  1758.     found: {}
  1759.     }
  1760.  
  1761.   typedef_type = type;
  1762.  
  1763.   /* No type at all: default to `int', and set EXPLICIT_INT
  1764.      because it was not a user-defined typedef.  */
  1765.  
  1766.   if (type == 0)
  1767.     {
  1768.       if (funcdef_flag && warn_return_type
  1769.       && ! (specbits & ((1 << (int) RID_LONG) | (1 << (int) RID_SHORT)
  1770.                 | (1 << (int) RID_SIGNED) | (1 << (int) RID_UNSIGNED))))
  1771.     warn_about_return_type = 1;
  1772.       explicit_int = 1;
  1773.       type = integer_type_node;
  1774.     }
  1775.  
  1776.   /* Now process the modifiers that were specified
  1777.      and check for invalid combinations.  */
  1778.  
  1779.   /* Long double is a special combination.  */
  1780.  
  1781.   if ((specbits & 1 << (int) RID_LONG) && type == double_type_node)
  1782.     {
  1783.       specbits &= ~ (1 << (int) RID_LONG);
  1784.       type = long_double_type_node;
  1785.     }
  1786.  
  1787.   /* Check all other uses of type modifiers.  */
  1788.  
  1789.   if (specbits & ((1 << (int) RID_LONG) | (1 << (int) RID_SHORT)
  1790.           | (1 << (int) RID_UNSIGNED) | (1 << (int) RID_SIGNED)))
  1791.     {
  1792.       if (!explicit_int && !explicit_char && !pedantic)
  1793.     error ("long, short, signed or unsigned used invalidly for `%s'", name);
  1794.       else if ((specbits & 1 << (int) RID_LONG) && (specbits & 1 << (int) RID_SHORT))
  1795.     error ("long and short specified together for `%s'", name);
  1796.       else if (((specbits & 1 << (int) RID_LONG) || (specbits & 1 << (int) RID_SHORT))
  1797.            && explicit_char)
  1798.     error ("long or short specified with char for `%s'", name);
  1799.       else if ((specbits & 1 << (int) RID_SIGNED) && (specbits & 1 << (int) RID_UNSIGNED))
  1800.     error ("signed and unsigned given together for `%s'", name);
  1801.       else
  1802.     {
  1803.       if (specbits & 1 << (int) RID_UNSIGNED)
  1804.         {
  1805.           if (longlong)
  1806.         type = long_long_unsigned_type_node;
  1807.           else if (specbits & 1 << (int) RID_LONG)
  1808.             type = long_unsigned_type_node;
  1809.           else if (specbits & 1 << (int) RID_SHORT)
  1810.         type = short_unsigned_type_node;
  1811.           else if (type == char_type_node)
  1812.         type = unsigned_char_type_node;
  1813.           else
  1814.         type = unsigned_type_node;
  1815.         }
  1816.       else if ((specbits & 1 << (int) RID_SIGNED)
  1817.            && type == char_type_node)
  1818.         type = signed_char_type_node;
  1819.       else if (longlong)
  1820.         type = long_long_integer_type_node;
  1821.       else if (specbits & 1 << (int) RID_LONG)
  1822.         type = long_integer_type_node;
  1823.       else if (specbits & 1 << (int) RID_SHORT)
  1824.         type = short_integer_type_node;
  1825.     }
  1826.     }
  1827.  
  1828.   /* Set CONSTP if this declaration is `const', whether by
  1829.      explicit specification or via a typedef.
  1830.      Likewise for VOLATILEP.  */
  1831.  
  1832.   constp = !! (specbits & 1 << (int) RID_CONST) + TREE_READONLY (type);
  1833.   volatilep = !! (specbits & 1 << (int) RID_VOLATILE) + TREE_VOLATILE (type);
  1834.   inlinep = !! (specbits & (1 << (int) RID_INLINE));
  1835.   if (constp > 1)
  1836.     warning ("duplicate `const'");
  1837.   if (volatilep > 1)
  1838.     warning ("duplicate `volatile'");
  1839.   type = TYPE_MAIN_VARIANT (type);
  1840.  
  1841.   /* Warn if two storage classes are given. Default to `auto'.  */
  1842.  
  1843.   {
  1844.     int nclasses = 0;
  1845.  
  1846.     if (specbits & 1 << (int) RID_AUTO) nclasses++;
  1847.     if (specbits & 1 << (int) RID_STATIC) nclasses++;
  1848.     if (specbits & 1 << (int) RID_EXTERN) nclasses++;
  1849.     if (specbits & 1 << (int) RID_REGISTER) nclasses++;
  1850.     if (specbits & 1 << (int) RID_TYPEDEF) nclasses++;
  1851.  
  1852.     /* Warn about storage classes that are invalid for certain
  1853.        kinds of declarations (parameters, typenames, etc.).  */
  1854.  
  1855.     if (nclasses > 1)
  1856.       error ("multiple storage classes in declaration of `%s'", name);
  1857.     else if (decl_context != NORMAL && nclasses > 0)
  1858.       {
  1859.     if (decl_context == PARM && specbits & 1 << (int) RID_REGISTER)
  1860.       ;
  1861.     else
  1862.       {
  1863.         error ((decl_context == FIELD
  1864.             ? "storage class specified for structure field `%s'"
  1865.             : (decl_context == PARM
  1866.                ? "storage class specified for parameter `%s'"
  1867.                : "storage class specified for typename")),
  1868.            name);
  1869.         specbits &= ~ ((1 << (int) RID_TYPEDEF) | (1 << (int) RID_REGISTER)
  1870.                | (1 << (int) RID_AUTO) | (1 << (int) RID_STATIC)
  1871.                | (1 << (int) RID_EXTERN));
  1872.       }
  1873.       }
  1874.     else if (current_binding_level == global_binding_level)
  1875.       {
  1876.     if (specbits & (1 << (int) RID_AUTO))
  1877.       error ("top-level declaration of `%s' specifies `auto'", name);
  1878.     if (specbits & (1 << (int) RID_REGISTER))
  1879.       error ("top-level declaration of `%s' specifies `register'", name);
  1880.       }
  1881.   }
  1882.  
  1883.   /* Now figure out the structure of the declarator proper.
  1884.      Descend through it, creating more complex types, until we reach
  1885.      the declared identifier (or NULL_TREE, in an absolute declarator).  */
  1886.  
  1887.   while (declarator && TREE_CODE (declarator) != IDENTIFIER_NODE)
  1888.     {
  1889.       if (type == error_mark_node)
  1890.     {
  1891.       declarator = TREE_OPERAND (declarator, 0);
  1892.       continue;
  1893.     }
  1894.  
  1895.       /* Each level of DECLARATOR is either an ARRAY_REF (for ...[..]),
  1896.      an INDIRECT_REF (for *...),
  1897.      a CALL_EXPR (for ...(...)),
  1898.      an identifier (for the name being declared)
  1899.      or a null pointer (for the place in an absolute declarator
  1900.      where the name was omitted).
  1901.      For the last two cases, we have just exited the loop.
  1902.  
  1903.      At this point, TYPE is the type of elements of an array,
  1904.      or for a function to return, or for a pointer to point to.
  1905.      After this sequence of ifs, TYPE is the type of the
  1906.      array or function or pointer, and DECLARATOR has had its
  1907.      outermost layer removed.  */
  1908.  
  1909.       if (TREE_CODE (declarator) == ARRAY_REF)
  1910.     {
  1911.       register tree itype = NULL_TREE;
  1912.       register tree size = TREE_OPERAND (declarator, 1);
  1913.  
  1914.       declarator = TREE_OPERAND (declarator, 0);
  1915.  
  1916.       /* Check for some types that there cannot be arrays of.  */
  1917.  
  1918.       if (type == void_type_node)
  1919.         {
  1920.           error ("declaration of `%s' as array of voids", name);
  1921.           type = error_mark_node;
  1922.         }
  1923.  
  1924.       if (TREE_CODE (type) == FUNCTION_TYPE)
  1925.         {
  1926.           error ("declaration of `%s' as array of functions", name);
  1927.           type = error_mark_node;
  1928.         }
  1929.  
  1930.       if (size == error_mark_node)
  1931.         type = error_mark_node;
  1932.  
  1933.       if (type == error_mark_node)
  1934.         continue;
  1935.  
  1936.       /* If size was specified, set ITYPE to a range-type for that size.
  1937.          Otherwise, ITYPE remains null.  finish_decl may figure it out
  1938.          from an initial value.  */
  1939.  
  1940.       if (size)
  1941.         {
  1942.           if (TREE_CODE (TREE_TYPE (size)) != INTEGER_TYPE
  1943.           && TREE_CODE (TREE_TYPE (size)) != ENUMERAL_TYPE)
  1944.         {
  1945.           error ("size of array `%s' has non-integer type", name);
  1946.           size = integer_one_node;
  1947.         }
  1948.           if (pedantic && integer_zerop (size))
  1949.         warning ("ANSI C forbids zero-size array `%s'", name);
  1950.           if (INT_CST_LT (size, integer_zero_node))
  1951.         {
  1952.           error ("size of array `%s' is negative", name);
  1953.           size = integer_one_node;
  1954.         }
  1955.           if (TREE_LITERAL (size))
  1956.         itype = make_index_type (build_int_2 (TREE_INT_CST_LOW (size) - 1, 0));
  1957.           else
  1958.         {
  1959.           if (pedantic)
  1960.             warning ("ANSI C forbids variable-size array `%s'", name);
  1961.           itype = build_binary_op (MINUS_EXPR, size, integer_one_node);
  1962.           itype = make_index_type (itype);
  1963.         }
  1964.         }
  1965.  
  1966.       /* Build the array type itself.  */
  1967.  
  1968.       type = build_array_type (type, itype);
  1969.     }
  1970.       else if (TREE_CODE (declarator) == CALL_EXPR)
  1971.     {
  1972.       /* Declaring a function type.
  1973.          Make sure we have a valid type for the function to return.  */
  1974.       if (type == error_mark_node)
  1975.         continue;
  1976.  
  1977.       /* Is this an error?  Should they be merged into TYPE here?  */
  1978.           if (constp || volatilep)
  1979.             warning ("function declared to return const or volatile result");
  1980.       constp = 0;
  1981.       volatilep = 0;
  1982.  
  1983.       /* Warn about some types functions can't return.  */
  1984.  
  1985.       if (TREE_CODE (type) == FUNCTION_TYPE)
  1986.         {
  1987.           error ("`%s' declared as function returning a function", name);
  1988.           type = integer_type_node;
  1989.         }
  1990.       if (TREE_CODE (type) == ARRAY_TYPE)
  1991.         {
  1992.           error ("`%s' declared as function returning an array", name);
  1993.           type = integer_type_node;
  1994.         }
  1995.  
  1996.       /* Construct the function type and go to the next
  1997.          inner layer of declarator.  */
  1998.  
  1999.       type =
  2000.         build_function_type (type,
  2001.                  grokparms (TREE_OPERAND (declarator, 1),
  2002.                         funcdef_flag
  2003.                         /* Say it's a definition
  2004.                            only for the CALL_EXPR
  2005.                            closest to the identifier.  */
  2006.                         && TREE_CODE (TREE_OPERAND (declarator, 0)) == IDENTIFIER_NODE));
  2007.       declarator = TREE_OPERAND (declarator, 0);
  2008.     }
  2009.       else if (TREE_CODE (declarator) == INDIRECT_REF)
  2010.     {
  2011.       /* Merge any constancy or volatility into the target type
  2012.          for the pointer.  */
  2013.  
  2014.       if (constp || volatilep)
  2015.         type = build_type_variant (type, constp, volatilep);
  2016.       constp = 0;
  2017.       volatilep = 0;
  2018.  
  2019.       type = build_pointer_type (type);
  2020.  
  2021.       /* Process a list of type modifier keywords
  2022.          (such as const or volatile) that were given inside the `*'.  */
  2023.  
  2024.       if (TREE_TYPE (declarator))
  2025.         {
  2026.           register tree typemodlist;
  2027.           int erred = 0;
  2028.           for (typemodlist = TREE_TYPE (declarator); typemodlist;
  2029.            typemodlist = TREE_CHAIN (typemodlist))
  2030.         {
  2031.           if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_CONST])
  2032.             constp++;
  2033.           else if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_VOLATILE])
  2034.             volatilep++;
  2035.           else if (!erred)
  2036.             {
  2037.               erred = 1;
  2038.               error ("invalid type modifier within pointer declarator");
  2039.             }
  2040.         }
  2041.           if (constp > 1)
  2042.         warning ("duplicate `const'");
  2043.           if (volatilep > 1)
  2044.         warning ("duplicate `volatile'");
  2045.         }
  2046.  
  2047.       declarator = TREE_OPERAND (declarator, 0);
  2048.     }
  2049.       else
  2050.     abort ();
  2051.  
  2052. /*      layout_type (type);  */
  2053.  
  2054.       /* @@ Should perhaps replace the following code by changes in
  2055.        * @@ stor_layout.c. */
  2056.       if (TREE_CODE (type) == FUNCTION_DECL)
  2057.     {
  2058.       /* A function variable in C should be Pmode rather than EPmode
  2059.          because it has just the address of a function, no static chain.*/
  2060.       TYPE_MODE (type) = Pmode;
  2061.     }
  2062.     }
  2063.  
  2064.   /* Now TYPE has the actual type.  */
  2065.  
  2066.   /* If this is declaring a typedef name, return a TYPE_DECL.  */
  2067.  
  2068.   if (specbits & (1 << (int) RID_TYPEDEF))
  2069.     {
  2070.       /* Note that the grammar rejects storage classes
  2071.      in typenames, fields or parameters */
  2072.       if (constp || volatilep)
  2073.     type = build_type_variant (type, constp, volatilep);
  2074.       if (resume_temporary)
  2075.     resume_temporary_allocation ();
  2076.       return build_decl (TYPE_DECL, declarator, type);
  2077.     }
  2078.  
  2079.   /* Detect the case of an array type of unspecified size
  2080.      which came, as such, direct from a typedef name.
  2081.      We must copy the type, so that each identifier gets
  2082.      a distinct type, so that each identifier's size can be
  2083.      controlled separately by its own initializer.  */
  2084.  
  2085.   if (type == typedef_type && TREE_CODE (type) == ARRAY_TYPE
  2086.       && TYPE_DOMAIN (type) == 0)
  2087.     {
  2088.       type = build_array_type (TREE_TYPE (type), TYPE_DOMAIN (type));
  2089.     }
  2090.  
  2091.   /* If this is a type name (such as, in a cast or sizeof),
  2092.      compute the type and return it now.  */
  2093.  
  2094.   if (decl_context == TYPENAME)
  2095.     {
  2096.       /* Note that the grammar rejects storage classes
  2097.      in typenames, fields or parameters */
  2098.       if (constp || volatilep)
  2099.     type = build_type_variant (type, constp, volatilep);
  2100.       if (resume_temporary)
  2101.     resume_temporary_allocation ();
  2102.       return type;
  2103.     }
  2104.  
  2105.   /* `void' at top level (not within pointer)
  2106.      is allowed only in typedefs or type names.
  2107.      We don't complain about parms either, but that is because
  2108.      a better error message can be made later.  */
  2109.  
  2110.   if (type == void_type_node && decl_context != PARM)
  2111.     {
  2112.       error ("variable or field `%s' declared void",
  2113.          IDENTIFIER_POINTER (declarator));
  2114.       type = integer_type_node;
  2115.     }
  2116.  
  2117.   /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
  2118.      or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE.  */
  2119.  
  2120.   {
  2121.     register tree decl;
  2122.  
  2123.     if (decl_context == PARM)
  2124.       {
  2125.     /* A parameter declared as an array of T is really a pointer to T.
  2126.        One declared as a function is really a pointer to a function.  */
  2127.  
  2128.     if (TREE_CODE (type) == ARRAY_TYPE)
  2129.       {
  2130.         /* Transfer const-ness of array into that of type pointed to.  */
  2131.         type = build_pointer_type
  2132.             (build_type_variant (TREE_TYPE (type), constp, volatilep));
  2133.         volatilep = constp = 0;
  2134.       }
  2135.     else if (TREE_CODE (type) == FUNCTION_TYPE)
  2136.       type = build_pointer_type (type);
  2137.  
  2138.     decl = build_decl (PARM_DECL, declarator, type);
  2139.  
  2140.     /* Compute the type actually passed in the parmlist,
  2141.        for the case where there is no prototype.
  2142.        (For example, shorts and chars are passed as ints.)
  2143.        When there is a prototype, this is overridden later.  */
  2144.  
  2145.     DECL_ARG_TYPE (decl) = type;
  2146.     if (type == float_type_node)
  2147.       DECL_ARG_TYPE (decl) = double_type_node;
  2148.     else if (TREE_CODE (type) == INTEGER_TYPE
  2149.          && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
  2150.       DECL_ARG_TYPE (decl) = integer_type_node;
  2151.       }
  2152.     else if (decl_context == FIELD)
  2153.       {
  2154.     /* Structure field.  It may not be a function.  */
  2155.  
  2156.     if (TREE_CODE (type) == FUNCTION_TYPE)
  2157.       {
  2158.         error ("field `%s' declared as a function",
  2159.            IDENTIFIER_POINTER (declarator));
  2160.         type = build_pointer_type (type);
  2161.       }
  2162.     else if (TYPE_SIZE (type) == 0)
  2163.       {
  2164.         error ("field `%s' has incomplete type",
  2165.            IDENTIFIER_POINTER (declarator));
  2166.         type = error_mark_node;
  2167.       }
  2168.     decl = build_decl (FIELD_DECL, declarator, type);
  2169.       }
  2170.     else if (TREE_CODE (type) == FUNCTION_TYPE)
  2171.       {
  2172.     if (specbits & ((1 << (int) RID_AUTO) | (1 << (int) RID_REGISTER)))
  2173.       error ("invalid storage class for function `%s'",
  2174.          IDENTIFIER_POINTER (declarator));
  2175.     /* Function declaration not at top level.
  2176.        Storage classes other than `extern' are not allowed
  2177.        and `extern' makes no difference.  */
  2178.     if (current_binding_level != global_binding_level
  2179.         && (specbits & ((1 << (int) RID_STATIC) | (1 << (int) RID_INLINE)))
  2180.         && pedantic)
  2181.       warning ("invalid storage class for function `%s'",
  2182.            IDENTIFIER_POINTER (declarator));
  2183.     decl = build_decl (FUNCTION_DECL, declarator, type);
  2184.  
  2185.     TREE_EXTERNAL (decl) = 1;
  2186.     /* Record presence of `static'.  */
  2187.     TREE_PUBLIC (decl) = !(specbits & (1 << (int) RID_STATIC));
  2188.     /* Record presence of `inline', if it is reasonable.  */
  2189.     if (inlinep)
  2190.       {
  2191.         tree last = tree_last (TYPE_ARG_TYPES (type));
  2192.  
  2193.         if (! strcmp (IDENTIFIER_POINTER (declarator), "main"))
  2194.           warning ("cannot inline function `main'");
  2195.         else if (last && TREE_VALUE (last) != void_type_node)
  2196.           error ("inline declaration ignored for function with `...'");
  2197.         else
  2198.           /* Assume that otherwise the function can be inlined.  */
  2199.           TREE_INLINE (decl) = 1;
  2200.       }
  2201.       }
  2202.     else
  2203.       {
  2204.     /* It's a variable.  */
  2205.  
  2206.     decl = build_decl (VAR_DECL, declarator, type);
  2207.  
  2208.     if (inlinep)
  2209.       warning_with_decl (decl, "variable `%s' declared `inline'");
  2210.  
  2211.     /* An uninitialized decl with `extern' is a reference.  */
  2212.     TREE_EXTERNAL (decl)
  2213.       = !initialized && (specbits & (1 << (int) RID_EXTERN));
  2214.     /* At top level, either `static' or no s.c. makes a definition
  2215.        (perhaps tentative), and absence of `static' makes it public.  */
  2216.     if (current_binding_level == global_binding_level)
  2217.       {
  2218.         TREE_PUBLIC (decl) = !(specbits & (1 << (int) RID_STATIC));
  2219.         TREE_STATIC (decl) = ! TREE_EXTERNAL (decl);
  2220.       }
  2221.     /* Not at top level, only `static' makes a static definition.  */
  2222.     else
  2223.       {
  2224.         TREE_STATIC (decl) = (specbits & (1 << (int) RID_STATIC)) != 0;
  2225.         /* `extern' with initialization is invalid if not at top level.  */
  2226.         if ((specbits & (1 << (int) RID_EXTERN)) && initialized)
  2227.           error ("`%s' has both `extern' and initializer", name);
  2228.       }
  2229.       }
  2230.  
  2231.     /* Record `register' declaration for warnings on &
  2232.        and in case doing stupid register allocation.  */
  2233.  
  2234.     if (specbits & (1 << (int) RID_REGISTER))
  2235.       TREE_REGDECL (decl) = 1;
  2236.  
  2237.     /* Record constancy and volatility.  */
  2238.  
  2239.     if (constp)
  2240.       TREE_READONLY (decl) = 1;
  2241.     if (volatilep)
  2242.       {
  2243.     TREE_VOLATILE (decl) = 1;
  2244.     TREE_THIS_VOLATILE (decl) = 1;
  2245.       }
  2246.  
  2247.     if (resume_temporary)
  2248.       resume_temporary_allocation ();
  2249.  
  2250.     return decl;
  2251.   }
  2252. }
  2253.  
  2254. /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
  2255.    MAXVAL should be the maximum value in the domain
  2256.    (one less than the length of the array).  */
  2257.  
  2258. tree
  2259. make_index_type (maxval)
  2260.      tree maxval;
  2261. {
  2262.   register tree itype = make_node (INTEGER_TYPE);
  2263.   int maxint = TREE_INT_CST_LOW (maxval);
  2264.   TYPE_PRECISION (itype) = BITS_PER_WORD;
  2265.   TYPE_MIN_VALUE (itype) = build_int_2 (0, 0);
  2266.   TREE_TYPE (TYPE_MIN_VALUE (itype)) = itype;
  2267.   TYPE_MAX_VALUE (itype) = maxval;
  2268.   TREE_TYPE (maxval) = itype;
  2269.   TYPE_MODE (itype) = SImode;
  2270.   TYPE_SIZE (itype) = TYPE_SIZE (long_integer_type_node);
  2271.   TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (long_integer_type_node);
  2272.   TYPE_ALIGN (itype) = TYPE_ALIGN (long_integer_type_node);
  2273.   return type_hash_canon (maxint > 0 ? maxint : - maxint, itype);
  2274. }
  2275.  
  2276. /* Decode the parameter-list info for a function type or function definition.
  2277.    The argument is the value returned by `get_parm_info' (or made in parse.y
  2278.    if there is an identifier list instead of a parameter decl list).
  2279.    These two functions are separate because when a function returns
  2280.    or receives functions then each is called multiple times but the order
  2281.    of calls is different.  The last call to `grokparms' is always the one
  2282.    that contains the formal parameter names of a function definition.
  2283.  
  2284.    Store in `last_function_parms' a chain of the decls of parms.
  2285.    Also store in `last_function_parm_tags' a chain of the struct and union
  2286.    tags declared among the parms.
  2287.  
  2288.    Return a list of arg types to use in the FUNCTION_TYPE for this function.
  2289.  
  2290.    FUNCDEF_FLAG is nonzero for a function definition, 0 for
  2291.    a mere declaration.  A nonempty identifier-list gets an error message
  2292.    when FUNCDEF_FLAG is zero.  */
  2293.  
  2294. static tree
  2295. grokparms (parms_info, funcdef_flag)
  2296.      tree parms_info;
  2297.      int funcdef_flag;
  2298. {
  2299.   tree first_parm = TREE_CHAIN (parms_info);
  2300.  
  2301.   last_function_parms = TREE_PURPOSE (parms_info);
  2302.   last_function_parm_tags = TREE_VALUE (parms_info);
  2303.  
  2304.   if (first_parm != 0
  2305.       && TREE_CODE (TREE_VALUE (first_parm)) == IDENTIFIER_NODE)
  2306.     {
  2307.       if (! funcdef_flag)
  2308.     warning ("parameter names (without types) in function declaration");
  2309.  
  2310.       last_function_parms = first_parm;
  2311.       return 0;
  2312.     }
  2313.   else
  2314.     {
  2315.       tree t;
  2316.       /* In a fcn definition, arg types must be complete.  */
  2317.       if (funcdef_flag)
  2318.     for (t = last_function_parms; t; t = TREE_CHAIN (t))
  2319.       {
  2320.         tree type = TREE_TYPE (t);
  2321.         if (TYPE_SIZE (type) == 0)
  2322.           {
  2323.         error ("parameter `%s' has incomplete type",
  2324.              IDENTIFIER_POINTER (DECL_NAME (t)));
  2325.         TREE_TYPE (t) = error_mark_node;
  2326.           }
  2327.       }
  2328.  
  2329.       return first_parm;
  2330.     }
  2331. }
  2332.  
  2333.  
  2334. /* Return a tree_list node with info on a parameter list just parsed.
  2335.    The TREE_PURPOSE is a chain of decls of those parms.
  2336.    The TREE_VALUE is a list of structure, union and enum tags defined.
  2337.    The TREE_CHAIN is a list of argument types to go in the FUNCTION_TYPE.
  2338.    This tree_list node is later fed to `grokparms'.
  2339.  
  2340.    VOID_AT_END nonzero means append `void' to the end of the type-list.
  2341.    Zero means the parmlist ended with an ellipsis so don't append `void'.  */
  2342.  
  2343. tree
  2344. get_parm_info (void_at_end)
  2345.      int void_at_end;
  2346. {
  2347.   register tree decl;
  2348.   register tree types = 0;
  2349.   tree link;
  2350.   int erred = 0;
  2351.   tree tags = gettags ();
  2352.   tree parms = nreverse (getdecls ());
  2353.  
  2354.   /* Just `void' (and no ellipsis) is special.  There are really no parms.  */
  2355.   if (void_at_end && parms != 0
  2356.       && TREE_CHAIN (parms) == 0
  2357.       && TREE_TYPE (parms) == void_type_node)
  2358.     {
  2359.       parms = NULL_TREE;
  2360.       storedecls (NULL_TREE);
  2361.       return tree_cons (NULL_TREE, NULL_TREE,
  2362.             tree_cons (NULL_TREE, void_type_node, NULL_TREE));
  2363.     }
  2364.  
  2365.   storedecls (parms);
  2366.  
  2367.   for (decl = parms; decl; decl = TREE_CHAIN (decl))
  2368.     {
  2369.       /* Since there is a prototype,
  2370.      args are passed in their declared types.  */
  2371.       tree type = TREE_TYPE (decl);
  2372.       DECL_ARG_TYPE (decl) = type;
  2373. #ifdef PROMOTE_PROTOTYPES
  2374.       if (TREE_CODE (type) == INTEGER_TYPE
  2375.       && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
  2376.     DECL_ARG_TYPE (decl) = integer_type_node;
  2377. #endif
  2378.  
  2379.       types = tree_cons (NULL_TREE, TREE_TYPE (decl), types);
  2380.       if (TREE_VALUE (types) == void_type_node && ! erred)
  2381.     {
  2382.       error ("`void' in parameter list must be the entire list");
  2383.       erred = 1;
  2384.     }
  2385.     }
  2386.  
  2387.   if (void_at_end)
  2388.     return tree_cons (parms, tags,
  2389.               nreverse (tree_cons (NULL_TREE, void_type_node, types)));
  2390.  
  2391.   return tree_cons (parms, tags, nreverse (types));
  2392. }
  2393.  
  2394. /* Get the struct, enum or union (CODE says which) with tag NAME.
  2395.    Define the tag as a forward-reference if it is not defined.  */
  2396.  
  2397. tree
  2398. xref_tag (code, name)
  2399.      enum tree_code code;
  2400.      tree name;
  2401. {
  2402.   /* If a cross reference is requested, look up the type
  2403.      already defined for this tag and return it.  */
  2404.  
  2405.   register tree ref = lookup_tag (code, name, current_binding_level, 0);
  2406.   if (ref) return ref;
  2407.  
  2408.   /* If no such tag is yet defined, create a forward-reference node
  2409.      and record it as the "definition".
  2410.      When a real declaration of this type is found,
  2411.      the forward-reference will be altered into a real type.  */
  2412.  
  2413.   ref = make_node (code);
  2414.   if (code == ENUMERAL_TYPE)
  2415.     {
  2416.       /* Give the type a default layout like unsigned int
  2417.      to avoid crashing if it does not get defined.  */
  2418.       TYPE_MODE (ref) = SImode;
  2419.       TYPE_ALIGN (ref) = TYPE_ALIGN (unsigned_type_node);
  2420.       TREE_UNSIGNED (ref) = 1;
  2421.       TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node);
  2422.       TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node);
  2423.       TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node);
  2424.     }
  2425.  
  2426.   pushtag (name, ref);
  2427.   return ref;
  2428. }
  2429.  
  2430. /* Make sure that the tag NAME is defined *in the current binding level*
  2431.    at least as a forward reference.
  2432.    CODE says which kind of tag NAME ought to be.  */
  2433.  
  2434. tree
  2435. start_struct (code, name)
  2436.      enum tree_code code;
  2437.      tree name;
  2438. {
  2439.   /* If there is already a tag defined at this binding level
  2440.      (as a forward reference), just return it.  */
  2441.  
  2442.   register tree ref = 0;
  2443.  
  2444.   if (name != 0)
  2445.     ref = lookup_tag (code, name, current_binding_level, 1);
  2446.   if (ref && TREE_CODE (ref) == code)
  2447.     {
  2448.       if (TYPE_FIELDS (ref))
  2449.     error ((code == UNION_TYPE ? "redefinition of `union %s'"
  2450.         : "redefinition of `struct %s'"),
  2451.            IDENTIFIER_POINTER (name));
  2452.  
  2453.       return ref;
  2454.     }
  2455.  
  2456.   /* Otherwise create a forward-reference just so the tag is in scope.  */
  2457.  
  2458.   ref = make_node (code);
  2459.   pushtag (name, ref);
  2460.   return ref;
  2461. }
  2462.  
  2463. /* Process the specs, declarator (NULL if omitted) and width (NULL if omitted)
  2464.    of a structure component, returning a FIELD_DECL node.
  2465.    WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node.
  2466.  
  2467.    This is done during the parsing of the struct declaration.
  2468.    The FIELD_DECL nodes are chained together and the lot of them
  2469.    are ultimately passed to `build_struct' to make the RECORD_TYPE node.  */
  2470.  
  2471. tree
  2472. grokfield (filename, line, declarator, declspecs, width)
  2473.      char *filename;
  2474.      int line;
  2475.      tree declarator, declspecs, width;
  2476. {
  2477.   register tree value = grokdeclarator (declarator, declspecs, FIELD, 0);
  2478.  
  2479.   finish_decl (value, NULL, NULL);
  2480.   DECL_INITIAL (value) = width;
  2481.  
  2482.   return value;
  2483. }
  2484.  
  2485. /* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T.
  2486.    FIELDLIST is a chain of FIELD_DECL nodes for the fields.  */
  2487.  
  2488. tree
  2489. finish_struct (t, fieldlist)
  2490.      register tree t, fieldlist;
  2491. {
  2492.   register tree x;
  2493.   int old;
  2494.   int round_up_size = 1;
  2495.  
  2496.   /* If this type was previously laid out as a forward reference,
  2497.      make sure we lay it out again.  */
  2498.  
  2499.   TYPE_SIZE (t) = 0;
  2500.  
  2501.   old = suspend_momentary ();
  2502.  
  2503.   if (fieldlist == 0 && pedantic)
  2504.     warning ((TREE_CODE (t) == UNION_TYPE ? "union has no members"
  2505.           : "structure has no members"));
  2506.  
  2507.   /* Install struct as DECL_CONTEXT of each field decl.
  2508.      Also process specified field sizes.
  2509.      Set DECL_SIZE_UNIT to the specified size, or 0 if none specified.
  2510.      The specified size is found in the DECL_INITIAL.
  2511.      Store 0 there, except for ": 0" fields (so we can find them
  2512.      and delete them, below).  */
  2513.  
  2514.   for (x = fieldlist; x; x = TREE_CHAIN (x))
  2515.     {
  2516.       DECL_CONTEXT (x) = t;
  2517.       DECL_SIZE_UNIT (x) = 0;
  2518.  
  2519.       /* If any field is const, the structure type is pseudo-const.  */
  2520.       if (TREE_READONLY (x))
  2521.     C_TYPE_FIELDS_READONLY (t) = 1;
  2522.       else
  2523.     {
  2524.       /* A field that is pseudo-const makes the structure likewise.  */
  2525.       tree t1 = TREE_TYPE (x);
  2526.       while (TREE_CODE (t1) == ARRAY_TYPE)
  2527.         t1 = TREE_TYPE (t1);
  2528.       if ((TREE_CODE (t1) == RECORD_TYPE || TREE_CODE (t1) == UNION_TYPE)
  2529.           && C_TYPE_FIELDS_READONLY (t1))
  2530.         C_TYPE_FIELDS_READONLY (t) = 1;
  2531.     }
  2532.  
  2533.       /* Detect invalid bit-field size.  */
  2534.       if (DECL_INITIAL (x) && TREE_CODE (DECL_INITIAL (x)) != INTEGER_CST)
  2535.     {
  2536.       error_with_decl (x, "bit-field `%s' width not an integer constant");
  2537.       DECL_INITIAL (x) = NULL;
  2538.     }
  2539.  
  2540.       /* Detect invalid bit-field type.  */
  2541.       if (DECL_INITIAL (x)
  2542.       && TREE_CODE (TREE_TYPE (x)) != INTEGER_TYPE
  2543.       && TREE_CODE (TREE_TYPE (x)) != ENUMERAL_TYPE)
  2544.     {
  2545.       error_with_decl (x, "bit-field `%s' has invalid type");
  2546.       DECL_INITIAL (x) = NULL;
  2547.     }
  2548.       if (DECL_INITIAL (x) && pedantic
  2549.       && TREE_TYPE (x) != integer_type_node
  2550.       && TREE_TYPE (x) != unsigned_type_node)
  2551.     warning_with_decl (x, "bit-field `%s' type invalid in ANSI C");
  2552.  
  2553.       /* Detect and ignore out of range field width.  */
  2554.       if (DECL_INITIAL (x))
  2555.     {
  2556.       register int width = TREE_INT_CST_LOW (DECL_INITIAL (x));
  2557.  
  2558.       if (width < 0)
  2559.         {
  2560.           DECL_INITIAL (x) = NULL;
  2561.           warning_with_decl (x, "negative width in bit-field `%s'");
  2562.         }
  2563.       else if (width > TYPE_PRECISION (TREE_TYPE (x)))
  2564.         {
  2565.           DECL_INITIAL (x) = NULL;
  2566.           warning_with_decl (x, "width of `%s' exceeds its type");
  2567.         }
  2568.     }
  2569.  
  2570.       /* Process valid field width.  */
  2571.       if (DECL_INITIAL (x))
  2572.     {
  2573.       register int width = TREE_INT_CST_LOW (DECL_INITIAL (x));
  2574.  
  2575.       if (width == 0)
  2576.         {
  2577.           /* field size 0 => mark following field as "aligned" */
  2578.           if (TREE_CHAIN (x))
  2579.         DECL_ALIGN (TREE_CHAIN (x))
  2580.           = MAX (DECL_ALIGN (TREE_CHAIN (x)), EMPTY_FIELD_BOUNDARY);
  2581.           /* field of size 0 at the end => round up the size.  */
  2582.           else
  2583.         round_up_size = EMPTY_FIELD_BOUNDARY;
  2584.         }
  2585.       else
  2586.         {
  2587.           DECL_INITIAL (x) = NULL;
  2588.           DECL_SIZE_UNIT (x) = width;
  2589.           TREE_PACKED (x) = 1;
  2590.           /* Traditionally a bit field is unsigned
  2591.          even if declared signed.  */
  2592.           if (flag_traditional
  2593.           && TREE_CODE (TREE_TYPE (x)) == INTEGER_TYPE)
  2594.         TREE_TYPE (x) = unsigned_type_node;
  2595.         }
  2596.     }
  2597.       else
  2598.     /* Non-bit-fields are aligned for their type.  */
  2599.     DECL_ALIGN (x) = MAX (DECL_ALIGN (x), TYPE_ALIGN (TREE_TYPE (x)));
  2600.     }
  2601.  
  2602.   /* Now DECL_INITIAL is null on all members except for zero-width bit-fields.
  2603.      And they have already done their work.  */
  2604.  
  2605.   /* Delete all zero-width bit-fields from the front of the fieldlist */
  2606.   while (fieldlist
  2607.      && DECL_INITIAL (fieldlist))
  2608.     fieldlist = TREE_CHAIN (fieldlist);
  2609.   /* Delete all such members from the rest of the fieldlist */
  2610.   for (x = fieldlist; x;)
  2611.     {
  2612.       if (TREE_CHAIN (x) && DECL_INITIAL (TREE_CHAIN (x)))
  2613.     TREE_CHAIN (x) = TREE_CHAIN (TREE_CHAIN (x));
  2614.       else x = TREE_CHAIN (x);
  2615.     }
  2616.  
  2617.   /* Delete all duplicate fields from the fieldlist */
  2618.   for (x = fieldlist; x && TREE_CHAIN (x);)
  2619.     /* Anonymous fields aren't duplicates.  */
  2620.     if (DECL_NAME (TREE_CHAIN (x)) == 0)
  2621.       x = TREE_CHAIN (x);
  2622.     else
  2623.       {
  2624.     register tree y = fieldlist;
  2625.       
  2626.     while (1)
  2627.       {
  2628.         if (DECL_NAME (y) == DECL_NAME (TREE_CHAIN (x)))
  2629.           break;
  2630.         if (y == x)
  2631.           break;
  2632.         y = TREE_CHAIN (y);
  2633.       }
  2634.     if (DECL_NAME (y) == DECL_NAME (TREE_CHAIN (x)))
  2635.       {
  2636.         error_with_decl (TREE_CHAIN (x), "duplicate member `%s'");
  2637.         TREE_CHAIN (x) = TREE_CHAIN (TREE_CHAIN (x));
  2638.       }
  2639.     else x = TREE_CHAIN (x);
  2640.       }
  2641.  
  2642.   /* Now we have the final fieldlist.  Record it,
  2643.      then lay out the structure or union (including the fields).  */
  2644.  
  2645.   TYPE_FIELDS (t) = fieldlist;
  2646.  
  2647.   /* If there's a :0 field at the end, round the size to the
  2648.      EMPTY_FIELD_BOUNDARY.  */
  2649.   TYPE_ALIGN (t) = round_up_size;
  2650.   
  2651.   layout_type (t);
  2652.  
  2653.   /* Promote each bit-field's type to int if it is narrower than that.  */
  2654.   for (x = fieldlist; x; x = TREE_CHAIN (x))
  2655.     if (TREE_PACKED (x)
  2656.     && TREE_CODE (TREE_TYPE (x)) == INTEGER_TYPE
  2657.     && (TREE_INT_CST_LOW (DECL_SIZE (x)) * DECL_SIZE_UNIT (x)
  2658.         < TYPE_PRECISION (integer_type_node)))
  2659.       TREE_TYPE (x) = integer_type_node;
  2660.  
  2661.   /* If this structure or union completes the type of any previous
  2662.      variable declaration, lay it out and output its rtl.  */
  2663.  
  2664.   if (current_binding_level->n_incomplete != 0)
  2665.     {
  2666.       tree decl;
  2667.       for (decl = current_binding_level->names; decl; decl = TREE_CHAIN (decl))
  2668.     if (TREE_TYPE (decl) == t
  2669.         && TREE_CODE (decl) != TYPE_DECL)
  2670.       {
  2671.         int toplevel = global_binding_level == current_binding_level;
  2672.         layout_decl (decl);
  2673.         rest_of_decl_compilation (decl, 0, toplevel, 0);
  2674.         if (! toplevel)
  2675.           expand_decl (decl);
  2676.         --current_binding_level->n_incomplete;
  2677.       }
  2678.     }
  2679.  
  2680.   resume_momentary (old);
  2681.  
  2682.   return t;
  2683. }
  2684.  
  2685. /* Begin compiling the definition of an enumeration type.
  2686.    NAME is its name (or null if anonymous).
  2687.    Returns the type object, as yet incomplete.
  2688.    Also records info about it so that build_enumerator
  2689.    may be used to declare the individual values as they are read.  */
  2690.  
  2691. tree
  2692. start_enum (name)
  2693.      tree name;
  2694. {
  2695.   register tree enumtype = 0;
  2696.  
  2697.   /* If this is the real definition for a previous forward reference,
  2698.      fill in the contents in the same object that used to be the
  2699.      forward reference.  */
  2700.  
  2701.   if (name != 0)
  2702.     enumtype = lookup_tag (ENUMERAL_TYPE, name, current_binding_level, 1);
  2703.  
  2704.   if (enumtype == 0 || TREE_CODE (enumtype) != ENUMERAL_TYPE)
  2705.     {
  2706.       enumtype = make_node (ENUMERAL_TYPE);
  2707.       pushtag (name, enumtype);
  2708.     }
  2709.  
  2710.   if (TYPE_VALUES (enumtype) != 0)
  2711.     {
  2712.       /* This enum is a named one that has been declared already.  */
  2713.       error ("redeclaration of `enum %s'", IDENTIFIER_POINTER (name));
  2714.  
  2715.       /* Completely replace its old definition.
  2716.      The old enumerators remain defined, however.  */
  2717.       TYPE_VALUES (enumtype) = 0;
  2718.     }
  2719.  
  2720.   /* Initially, set up this enum as like `int'
  2721.      so that we can create the enumerators' declarations and values.
  2722.      Later on, the precision of the type may be changed and
  2723.      it may be laid out again.  */
  2724.  
  2725.   TYPE_PRECISION (enumtype) = TYPE_PRECISION (integer_type_node);
  2726.   TYPE_SIZE (enumtype) = 0;
  2727.   fixup_unsigned_type (enumtype);
  2728.  
  2729.   enum_next_value = integer_zero_node;
  2730.  
  2731.   return enumtype;
  2732. }
  2733.  
  2734. /* After processing and defining all the values of an enumeration type,
  2735.    install their decls in the enumeration type and finish it off.
  2736.    ENUMTYPE is the type object and VALUES a list of name-value pairs.
  2737.    Returns ENUMTYPE.  */
  2738.  
  2739. tree
  2740. finish_enum (enumtype, values)
  2741.      register tree enumtype, values;
  2742. {
  2743.   register tree pair = values;
  2744.   register long maxvalue = 0;
  2745.   register long minvalue = 0;
  2746.   register int i;
  2747.  
  2748.   TYPE_VALUES (enumtype) = values;
  2749.  
  2750.   /* Calculate the maximum value of any enumerator in this type.  */
  2751.  
  2752.   for (pair = values; pair; pair = TREE_CHAIN (pair))
  2753.     {
  2754.       int value = TREE_INT_CST_LOW (TREE_VALUE (pair));
  2755.       if (pair == values)
  2756.     minvalue = maxvalue = value;
  2757.       else
  2758.     {
  2759.       if (value > maxvalue)
  2760.         maxvalue = value;
  2761.       if (value < minvalue)
  2762.         minvalue = value;
  2763.     }
  2764.     }
  2765.  
  2766. #if 0
  2767.   /* Determine the precision this type needs, lay it out, and define it.  */
  2768.  
  2769.   for (i = maxvalue; i; i >>= 1)
  2770.     TYPE_PRECISION (enumtype)++;
  2771.  
  2772.   if (!TYPE_PRECISION (enumtype))
  2773.     TYPE_PRECISION (enumtype) = 1;
  2774.  
  2775.   /* Cancel the laying out previously done for the enum type,
  2776.      so that fixup_unsigned_type will do it over.  */
  2777.   TYPE_SIZE (enumtype) = 0;
  2778.  
  2779.   fixup_unsigned_type (enumtype);
  2780. #endif
  2781.  
  2782.   TREE_INT_CST_LOW (TYPE_MAX_VALUE (enumtype)) = maxvalue;
  2783.  
  2784.   /* An enum can have some negative values; then it is signed.  */
  2785.   if (minvalue < 0)
  2786.     {
  2787.       TREE_INT_CST_LOW (TYPE_MIN_VALUE (enumtype)) = minvalue;
  2788.       TREE_INT_CST_HIGH (TYPE_MIN_VALUE (enumtype)) = -1;
  2789.       TREE_UNSIGNED (enumtype) = 0;
  2790.     }
  2791.   return enumtype;
  2792. }
  2793.  
  2794. /* Build and install a CONST_DECL for one value of the
  2795.    current enumeration type (one that was begun with start_enum).
  2796.    Return a tree-list containing the name and its value.
  2797.    Assignment of sequential values by default is handled here.  */
  2798.  
  2799. tree
  2800. build_enumerator (name, value)
  2801.      tree name, value;
  2802. {
  2803.   register tree decl;
  2804.  
  2805.   /* Validate and default VALUE.  */
  2806.  
  2807.   if (value != 0 && TREE_CODE (value) != INTEGER_CST)
  2808.     {
  2809.       error ("enumerator value for `%s' not integer constant",
  2810.          IDENTIFIER_POINTER (name));
  2811.       value = 0;
  2812.     }
  2813.  
  2814.   /* Default based on previous value.  */
  2815.   if (value == 0)
  2816.     value = enum_next_value;
  2817.  
  2818.   /* Set basis for default for next value.  */
  2819.   enum_next_value = build_binary_op_nodefault (PLUS_EXPR, value,
  2820.                            integer_one_node);
  2821.  
  2822.   /* Now create a declaration for the enum value name.  */
  2823.  
  2824.   decl = build_decl (CONST_DECL, name, integer_type_node);
  2825.   DECL_INITIAL (decl) = value;
  2826.   TREE_TYPE (value) = integer_type_node;
  2827.   pushdecl (decl);
  2828.  
  2829.   return build_tree_list (name, value);
  2830. }
  2831.  
  2832. /* Create the FUNCTION_DECL for a function definition.
  2833.    LINE1 is the line number that the definition absolutely begins on.
  2834.    LINE2 is the line number that the name of the function appears on.
  2835.    DECLSPECS and DECLARATOR are the parts of the declaration;
  2836.    they describe the function's name and the type it returns,
  2837.    but twisted together in a fashion that parallels the syntax of C.
  2838.  
  2839.    This function creates a binding context for the function body
  2840.    as well as setting up the FUNCTION_DECL in current_function_decl.
  2841.  
  2842.    Returns 1 on success.  If the DECLARATOR is not suitable for a function
  2843.    (it defines a datum instead), we return 0, which tells
  2844.    yyparse to report a parse error.  */
  2845.  
  2846. int
  2847. start_function (declspecs, declarator)
  2848.      tree declarator, declspecs;
  2849. {
  2850.   tree decl1, old_decl;
  2851.   tree restype;
  2852.  
  2853.   current_function_returns_value = 0;  /* Assume, until we see it does. */
  2854.   current_function_returns_null = 0;
  2855.   warn_about_return_type = 0;
  2856.  
  2857.   decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1);
  2858.  
  2859.   /* If the declarator is not suitable for a function definition,
  2860.      cause a syntax error.  */
  2861.   if (decl1 == 0)
  2862.     return 0;
  2863.  
  2864.   current_function_decl = decl1;
  2865.  
  2866.   announce_function (current_function_decl);
  2867.  
  2868.   if (TYPE_SIZE (TREE_TYPE (TREE_TYPE (decl1))) == 0)
  2869.     {
  2870.       error ("return-type is an incomplete type");
  2871.       /* Make it return void instead.  */
  2872.       TREE_TYPE (decl1)
  2873.     = build_function_type (void_type_node,
  2874.                    TYPE_ARG_TYPES (TREE_TYPE (decl1)));
  2875.     }
  2876.  
  2877.   if (warn_about_return_type)
  2878.     warning ("return-type defaults to `int'");
  2879.  
  2880.   /* Save the parm names or decls from this function's declarator
  2881.      where store_parm_decls will find them.  */
  2882.   current_function_parms = last_function_parms;
  2883.   current_function_parm_tags = last_function_parm_tags;
  2884.  
  2885.   /* Make the init_value nonzero so pushdecl knows this is not tentative.
  2886.      error_mark_node is replaced below (in poplevel) with the LET_STMT.  */
  2887.   DECL_INITIAL (current_function_decl) = error_mark_node;
  2888.  
  2889.   /* If this definition isn't a prototype and we had a prototype declaration
  2890.      before, copy the arg type info from that prototype.  */
  2891.   old_decl = lookup_name_current_level (DECL_NAME (current_function_decl));
  2892.   if (old_decl != 0
  2893.       && TREE_TYPE (TREE_TYPE (current_function_decl)) == TREE_TYPE (TREE_TYPE (old_decl))
  2894.       && TYPE_ARG_TYPES (TREE_TYPE (current_function_decl)) == 0)
  2895.     TREE_TYPE (current_function_decl) = TREE_TYPE (old_decl);
  2896.  
  2897.   /* This is a definition, not a reference.  */
  2898.   TREE_EXTERNAL (current_function_decl) = 0;
  2899.   /* This function exists in static storage.
  2900.      (This does not mean `static' in the C sense!)  */
  2901.   TREE_STATIC (current_function_decl) = 1;
  2902.  
  2903.   /* Record the decl so that the function name is defined.
  2904.      If we already have a decl for this name, and it is a FUNCTION_DECL,
  2905.      use the old decl.  */
  2906.  
  2907.   current_function_decl = pushdecl (current_function_decl);
  2908.  
  2909.   pushlevel (0);
  2910.   current_binding_level->parm_flag = 1;
  2911.  
  2912.   make_function_rtl (current_function_decl);
  2913.  
  2914.   /* Allocate further tree nodes temporarily during compilation
  2915.      of this function only.  */
  2916.   temporary_allocation ();
  2917.  
  2918.   restype = TREE_TYPE (TREE_TYPE (current_function_decl));
  2919.   /* Promote the value to int before returning it.  */
  2920.   if (TREE_CODE (restype) == INTEGER_TYPE
  2921.       && TYPE_PRECISION (restype) < TYPE_PRECISION (integer_type_node))
  2922.     restype = integer_type_node;
  2923.   DECL_RESULT (current_function_decl)
  2924.     = build_decl (RESULT_DECL, value_identifier, restype);
  2925.  
  2926.   /* Make the FUNCTION_DECL's contents appear in a local tree dump
  2927.      and make the FUNCTION_DECL itself not appear in the permanent dump.  */
  2928.  
  2929.   TREE_PERMANENT (current_function_decl) = 0;
  2930.  
  2931.   /* If this fcn was already referenced via a block-scope `extern' decl
  2932.      (or an implicit decl), propagate certain information about the usage.  */
  2933.   if (TREE_ADDRESSABLE (DECL_NAME (current_function_decl)))
  2934.     TREE_ADDRESSABLE (current_function_decl) = 1;
  2935.  
  2936.   return 1;
  2937. }
  2938.  
  2939. /* Store the parameter declarations into the current function declaration.
  2940.    This is called after parsing the parameter declarations, before
  2941.    digesting the body of the function.  */
  2942.  
  2943. void
  2944. store_parm_decls ()
  2945. {
  2946.   register tree fndecl = current_function_decl;
  2947.   register tree parm;
  2948.  
  2949.   /* This is either a chain of PARM_DECLs (if a prototype was used)
  2950.      or a list of IDENTIFIER_NODEs (for an old-fashioned C definition).  */
  2951.   tree specparms = current_function_parms;
  2952.  
  2953.   /* This is a list of types declared among parms in a prototype.  */
  2954.   tree parmtags = current_function_parm_tags;
  2955.  
  2956.   /* This is a chain of PARM_DECLs from old-style parm declarations.  */
  2957.   register tree parmdecls = getdecls ();
  2958.  
  2959.   /* This is a chain of any other decls that came in among the parm
  2960.      declarations.  If a parm is declared with  enum {foo, bar} x;
  2961.      then CONST_DECLs for foo and bar are put here.  */
  2962.   tree nonparms = 0;
  2963.  
  2964.   if (specparms != 0 && TREE_CODE (specparms) == PARM_DECL)
  2965.     {
  2966.       /* This case is when the function was defined with an ANSI prototype.
  2967.      The parms already have decls, so we need not do anything here
  2968.      except record them as in effect
  2969.      and complain if any redundant old-style parm decls were written.  */
  2970.  
  2971.       register tree next;
  2972.  
  2973.       if (parmdecls != 0)
  2974.     error_with_decl (fndecl,
  2975.              "parm types given both in parmlist and separately");
  2976.  
  2977.       for (parm = nreverse (specparms); parm; parm = next)
  2978.     {
  2979.       next = TREE_CHAIN (parm);
  2980.       if (DECL_NAME (parm) == 0)
  2981.         error_with_decl (parm, "parameter name omitted");
  2982.       else if (TREE_TYPE (parm) == void_type_node)
  2983.         error_with_decl (parm, "parameter `%s' declared void");
  2984.       else
  2985.         pushdecl (parm);
  2986.     }
  2987.  
  2988.       /* Get the decls in their original chain order
  2989.      and record in the function.  */
  2990.       DECL_ARGUMENTS (fndecl) = getdecls ();
  2991.  
  2992.       storetags (chainon (parmtags, gettags ()));
  2993.     }
  2994.   else
  2995.     {
  2996.       /* SPECPARMS is an identifier list--a chain of TREE_LIST nodes
  2997.      each with a parm name as the TREE_VALUE.
  2998.  
  2999.      PARMDECLS is a list of declarations for parameters.
  3000.      Warning! It can also contain CONST_DECLs which are not parameters
  3001.      but are names of enumerators of any enum types
  3002.      declared among the parameters.
  3003.  
  3004.      First match each formal parameter name with its declaration.
  3005.      Associate decls with the names and store the decls
  3006.      into the TREE_PURPOSE slots.  */
  3007.  
  3008.       for (parm = specparms; parm; parm = TREE_CHAIN (parm))
  3009.     {
  3010.       register tree tail, found = NULL;
  3011.  
  3012.       if (TREE_VALUE (parm) == 0)
  3013.         {
  3014.           error_with_decl (fndecl, "parameter name missing from parameter list");
  3015.           TREE_PURPOSE (parm) = 0;
  3016.           continue;
  3017.         }
  3018.  
  3019.       /* See if any of the parmdecls specifies this parm by name.
  3020.          Ignore any enumerator decls.  */
  3021.       for (tail = parmdecls; tail; tail = TREE_CHAIN (tail))
  3022.         if (DECL_NAME (tail) == TREE_VALUE (parm)
  3023.         && TREE_CODE (tail) == PARM_DECL)
  3024.           {
  3025.         found = tail;
  3026.         break;
  3027.           }
  3028.  
  3029.       /* If declaration already marked, we have a duplicate name.
  3030.          Complain, and don't use this decl twice.   */
  3031.       if (found && DECL_CONTEXT (found) != 0)
  3032.         {
  3033.           error_with_decl (found, "multiple parameters named `%s'");
  3034.           found = 0;
  3035.         }
  3036.  
  3037.       /* If the declaration says "void", complain and ignore it.  */
  3038.       if (found && TREE_TYPE (found) == void_type_node)
  3039.         {
  3040.           error_with_decl (found, "parameter `%s' declared void");
  3041.           TREE_TYPE (found) = integer_type_node;
  3042.           DECL_ARG_TYPE (found) = integer_type_node;
  3043.           layout_decl (found, 0);
  3044.         }
  3045.  
  3046.       /* If no declaration found, default to int.  */
  3047.       if (!found)
  3048.         {
  3049.           found = build_decl (PARM_DECL, TREE_VALUE (parm),
  3050.                   integer_type_node);
  3051.           DECL_ARG_TYPE (found) = TREE_TYPE (found);
  3052.           DECL_SOURCE_LINE (found) = DECL_SOURCE_LINE (fndecl);
  3053.           DECL_SOURCE_FILE (found) = DECL_SOURCE_FILE (fndecl);
  3054.           pushdecl (found);
  3055.         }
  3056.  
  3057.       TREE_PURPOSE (parm) = found;
  3058.  
  3059.       /* Mark this decl as "already found" -- see test, above.
  3060.          It is safe to clobber DECL_CONTEXT temporarily
  3061.          because the final values are not stored until
  3062.          the `poplevel' in `finish_function'.  */
  3063.       DECL_CONTEXT (found) = error_mark_node;
  3064.     }
  3065.  
  3066.       /* Complain about declarations not matched with any names.
  3067.      Put any enumerator constants onto the list NONPARMS.  */
  3068.  
  3069.       nonparms = 0;
  3070.       for (parm = parmdecls; parm; )
  3071.     {
  3072.       tree next = TREE_CHAIN (parm);
  3073.       TREE_CHAIN (parm) = 0;
  3074.  
  3075.       /* Complain about args with incomplete types.  */
  3076.       if (TYPE_SIZE (TREE_TYPE (parm)) == 0)
  3077.         {
  3078.           error_with_decl (parm, "parameter `%s' has incomplete type");
  3079.           TREE_TYPE (parm) = error_mark_node;
  3080.         }
  3081.  
  3082.       if (TREE_CODE (parm) != PARM_DECL)
  3083.         nonparms = chainon (nonparms, parm);
  3084.  
  3085.       else if (DECL_CONTEXT (parm) == 0)
  3086.         {
  3087.           error_with_decl (parm,
  3088.                    "declaration for parameter `%s' but no such parameter");
  3089.           /* Pretend the parameter was not missing.
  3090.          This gets us to a standard state and minimizes
  3091.          further error messages.  */
  3092.           specparms
  3093.         = chainon (specparms,
  3094.                tree_cons (parm, NULL_TREE, NULL_TREE));
  3095.         }
  3096.  
  3097.       parm = next;
  3098.     }
  3099.  
  3100.       /* Chain the declarations together in the order of the list of names.  */
  3101.       /* Store that chain in the function decl, replacing the list of names.  */
  3102.       parm = specparms;
  3103.       DECL_ARGUMENTS (fndecl) = 0;
  3104.       {
  3105.     register tree last;
  3106.     for (last = 0; parm; parm = TREE_CHAIN (parm))
  3107.       if (TREE_PURPOSE (parm))
  3108.         {
  3109.           if (last == 0)
  3110.         DECL_ARGUMENTS (fndecl) = TREE_PURPOSE (parm);
  3111.           else
  3112.         TREE_CHAIN (last) = TREE_PURPOSE (parm);
  3113.           last = TREE_PURPOSE (parm);
  3114.           TREE_CHAIN (last) = 0;
  3115.           DECL_CONTEXT (last) = 0;
  3116.         }
  3117.       }
  3118.  
  3119.       /* If there was a previous prototype,
  3120.      set the DECL_ARG_TYPE of each argument according to
  3121.      the type previously specified, and report any mismatches.  */
  3122.  
  3123.       if (TYPE_ARG_TYPES (TREE_TYPE (fndecl)))
  3124.     {
  3125.       register tree type;
  3126.       for (parm = DECL_ARGUMENTS (fndecl),
  3127.            type = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
  3128.            parm || (type && TREE_VALUE (type) != void_type_node);
  3129.            parm = TREE_CHAIN (parm), type = TREE_CHAIN (type))
  3130.         {
  3131.           if (parm == 0 || type == 0
  3132.           || TREE_VALUE (type) == void_type_node)
  3133.         {
  3134.           error ("argument decls of `%s' don't match prototype",
  3135.              IDENTIFIER_POINTER (DECL_NAME (fndecl)));
  3136.           break;
  3137.         }
  3138.           /* Type for passing arg must be consistent
  3139.          with that declared for the arg.  */
  3140.           if (! comptypes (DECL_ARG_TYPE (parm), TREE_VALUE (type)))
  3141.         error ("argument `%s' doesn't match function prototype",
  3142.                IDENTIFIER_POINTER (DECL_NAME (parm)));
  3143.         }
  3144.     }
  3145.     }
  3146.  
  3147.   /* Now store the final chain of decls for the arguments
  3148.      as the decl-chain of the current lexical scope.
  3149.      Put the enumerators in as well, at the front so that
  3150.      DECL_ARGUMENTS is not modified.  */
  3151.  
  3152.   storedecls (chainon (nonparms, DECL_ARGUMENTS (fndecl)));
  3153.  
  3154.   /* Initialize the RTL code for the function.  */
  3155.  
  3156.   expand_function_start (fndecl);
  3157. }
  3158.  
  3159. /* Finish up a function declaration and compile that function
  3160.    all the way to assembler language output.  The free the storage
  3161.    for the function definition.
  3162.  
  3163.    This is called after parsing the body of the function definition.
  3164.    STMTS is the chain of statements that makes up the function body.  */
  3165.  
  3166. void
  3167. finish_function ()
  3168. {
  3169.   register tree fndecl = current_function_decl;
  3170.  
  3171. /*  TREE_READONLY (fndecl) = 1;
  3172.     This caused &foo to be of type ptr-to-const-function
  3173.     which then got a warning when stored in a ptr-to-function variable.  */
  3174.  
  3175.   poplevel (1, 0, 1);
  3176.  
  3177.   /* Must mark the RESULT_DECL as being in this function.  */
  3178.  
  3179.   DECL_CONTEXT (DECL_RESULT (fndecl)) = DECL_INITIAL (fndecl);
  3180.  
  3181.   /* Generate rtl for function exit.  */
  3182.   expand_function_end (input_filename, lineno);
  3183.  
  3184.   if (warn_return_type)
  3185.     /* So we can tell if jump_optimize sets it to 1.  */
  3186.     current_function_returns_null = 0;
  3187.  
  3188.   /* Run the optimizers and output the assembler code for this function.  */
  3189.   rest_of_compilation (fndecl);
  3190.  
  3191.   if (warn_return_type && current_function_returns_null
  3192.       && TREE_TYPE (TREE_TYPE (fndecl)) != void_type_node)
  3193.     /* If this function returns non-void and control can drop through,
  3194.        complain.  */
  3195.     warning ("control reaches end of non-void function");
  3196.   /* With just -W, complain only if function returns both with
  3197.      and without a value.  */
  3198.   else if (extra_warnings
  3199.       && current_function_returns_value && current_function_returns_null)
  3200.     warning ("this function may return with or without a value");
  3201.  
  3202.   /* Free all the tree nodes making up this function.  */
  3203.   /* Switch back to allocating nodes permanently
  3204.      until we start another function.  */
  3205.   permanent_allocation ();
  3206.  
  3207.   if (DECL_SAVED_INSNS (fndecl) == 0)
  3208.     {
  3209.       /* Stop pointing to the local nodes about to be freed.  */
  3210.       /* But DECL_INITIAL must remain nonzero so we know this
  3211.      was an actual function definition.  */
  3212.       DECL_INITIAL (fndecl) = error_mark_node;
  3213.       DECL_ARGUMENTS (fndecl) = 0;
  3214.       DECL_RESULT (fndecl) = 0;
  3215.     }
  3216.  
  3217.   /* Let the error reporting routines know that we're outside a function.  */
  3218.   current_function_decl = NULL;
  3219. }
  3220.